@kendew-agency/react-feedback-layer 0.2.1 → 0.3.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 +57 -15
- package/dist/{comment.types-CSGuc1D_.d.cts → comment.types-D2tC4rfE.d.cts} +24 -3
- package/dist/{comment.types-CSGuc1D_.d.ts → comment.types-D2tC4rfE.d.ts} +24 -3
- package/dist/index.cjs +35 -8
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +35 -8
- package/dist/types.d.cts +2 -2
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,9 +40,9 @@ import {
|
|
|
40
40
|
} from '@kendew-agency/react-feedback-layer';
|
|
41
41
|
|
|
42
42
|
function App() {
|
|
43
|
-
const handleConfirm = async (comments) => {
|
|
43
|
+
const handleConfirm = async (comments, projectId) => {
|
|
44
44
|
// Save comments to your database
|
|
45
|
-
await saveToDatabase(comments);
|
|
45
|
+
await saveToDatabase(comments, projectId);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const handleResolve = async (comments) => {
|
|
@@ -50,11 +50,16 @@ function App() {
|
|
|
50
50
|
await resolveInDatabase(comments);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
const handleError = (error) => {
|
|
54
|
+
console.error('Comment error:', error.code, error.message);
|
|
55
|
+
};
|
|
56
|
+
|
|
53
57
|
return (
|
|
54
58
|
<CommentContextProvider
|
|
55
59
|
currentUser={{ name: 'John Doe', id: 'user-123' }}
|
|
56
60
|
onConfirm={handleConfirm}
|
|
57
61
|
onResolve={handleResolve}
|
|
62
|
+
onError={handleError}
|
|
58
63
|
initialComments={[]}
|
|
59
64
|
>
|
|
60
65
|
<CommentOverlay>
|
|
@@ -132,13 +137,13 @@ interface CommentOverlayProps {
|
|
|
132
137
|
};
|
|
133
138
|
|
|
134
139
|
// Callback when user confirms draft comments
|
|
135
|
-
onConfirm: (comments: ConfirmedComment[]) => Promise<void>;
|
|
140
|
+
onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
|
|
136
141
|
|
|
137
142
|
// Callback when user resolves comments
|
|
138
143
|
onResolve: (comments: ConfirmedComment[]) => Promise<void>;
|
|
139
144
|
|
|
140
|
-
// Callback to handle errors
|
|
141
|
-
onError
|
|
145
|
+
// Callback to handle errors
|
|
146
|
+
onError: (error: KnownError) => void;
|
|
142
147
|
|
|
143
148
|
// Optional configuration for the comment layer
|
|
144
149
|
config?: {
|
|
@@ -152,6 +157,9 @@ interface CommentOverlayProps {
|
|
|
152
157
|
hideResolving?: boolean;
|
|
153
158
|
};
|
|
154
159
|
};
|
|
160
|
+
|
|
161
|
+
// Optional project ID to attach to all comments in this overlay
|
|
162
|
+
projectId?: string;
|
|
155
163
|
}
|
|
156
164
|
```
|
|
157
165
|
|
|
@@ -161,8 +169,9 @@ interface CommentOverlayProps {
|
|
|
161
169
|
<CommentContextProvider
|
|
162
170
|
currentUser={{ name: 'Jane Smith', id: '456', avatar: '/avatar.jpg' }}
|
|
163
171
|
initialComments={existingComments}
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
projectId="proj_123456789"
|
|
173
|
+
onConfirm={async (comments, projectId) => {
|
|
174
|
+
await api.createComments(comments, projectId);
|
|
166
175
|
}}
|
|
167
176
|
onResolve={async (comments) => {
|
|
168
177
|
await api.resolveComments(comments);
|
|
@@ -472,6 +481,7 @@ interface CommentContext {
|
|
|
472
481
|
confirmComments: () => Promise<{ error: Error | DOMException | null }>;
|
|
473
482
|
resolveComments: () => Promise<{ error: Error | DOMException | null }>;
|
|
474
483
|
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
484
|
+
triggerError: (error: KnownError) => void;
|
|
475
485
|
}
|
|
476
486
|
```
|
|
477
487
|
|
|
@@ -570,6 +580,7 @@ type CommentType = {
|
|
|
570
580
|
resolvedAt?: Date;
|
|
571
581
|
status: "draft" | "published" | "resolving" | "resolved";
|
|
572
582
|
indicator?: Indicator | null;
|
|
583
|
+
projectId?: string;
|
|
573
584
|
};
|
|
574
585
|
```
|
|
575
586
|
|
|
@@ -675,10 +686,10 @@ function App() {
|
|
|
675
686
|
return (
|
|
676
687
|
<CommentContextProvider
|
|
677
688
|
currentUser={{ name: 'John Doe', id: '123' }}
|
|
678
|
-
onConfirm={async (comments) => {
|
|
689
|
+
onConfirm={async (comments, projectId) => {
|
|
679
690
|
const response = await fetch('/api/comments', {
|
|
680
691
|
method: 'POST',
|
|
681
|
-
body: JSON.stringify(comments),
|
|
692
|
+
body: JSON.stringify({ comments, projectId }),
|
|
682
693
|
});
|
|
683
694
|
if (!response.ok) {
|
|
684
695
|
throw new Error('Failed to save comments');
|
|
@@ -749,6 +760,7 @@ function App() {
|
|
|
749
760
|
subscription={subscription}
|
|
750
761
|
onConfirm={saveComments}
|
|
751
762
|
onResolve={resolveComments}
|
|
763
|
+
onError={(error) => console.error(error)}
|
|
752
764
|
>
|
|
753
765
|
{/* ... */}
|
|
754
766
|
</CommentContextProvider>
|
|
@@ -919,6 +931,27 @@ function VisibilityControls() {
|
|
|
919
931
|
|
|
920
932
|
## Advanced Patterns
|
|
921
933
|
|
|
934
|
+
### Project ID
|
|
935
|
+
|
|
936
|
+
Attach a project ID to all comments created within an overlay. This is useful for multi-project setups where you need to associate comments with a specific project in your database.
|
|
937
|
+
|
|
938
|
+
```tsx
|
|
939
|
+
<CommentContextProvider
|
|
940
|
+
currentUser={currentUser}
|
|
941
|
+
projectId="proj_123456789"
|
|
942
|
+
onConfirm={async (comments, projectId) => {
|
|
943
|
+
// projectId is passed through to your callback
|
|
944
|
+
await api.createComments(comments, projectId);
|
|
945
|
+
}}
|
|
946
|
+
onResolve={resolveComments}
|
|
947
|
+
onError={handleError}
|
|
948
|
+
>
|
|
949
|
+
{children}
|
|
950
|
+
</CommentContextProvider>
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
Each comment created within this provider will have the `projectId` field set, which you can use for filtering and organizing comments per project.
|
|
954
|
+
|
|
922
955
|
### Programmatic Comment Creation
|
|
923
956
|
|
|
924
957
|
```tsx
|
|
@@ -948,9 +981,9 @@ function CustomTool() {
|
|
|
948
981
|
|
|
949
982
|
### Error Handling
|
|
950
983
|
|
|
951
|
-
|
|
984
|
+
The `onError` callback is required and handles all error types, including overlay interaction errors like attempting to add a comment while editing or dismissing an empty comment.
|
|
952
985
|
|
|
953
|
-
**1. Using the `onError` callback
|
|
986
|
+
**1. Using the `onError` callback:**
|
|
954
987
|
|
|
955
988
|
```tsx
|
|
956
989
|
<CommentContextProvider
|
|
@@ -958,9 +991,8 @@ You can handle errors in two ways:
|
|
|
958
991
|
onConfirm={saveComments}
|
|
959
992
|
onResolve={resolveComments}
|
|
960
993
|
onError={(error) => {
|
|
961
|
-
console.error('Comment operation failed:', error);
|
|
962
|
-
|
|
963
|
-
toast.error('Failed to save comments. Please try again.');
|
|
994
|
+
console.error('Comment operation failed:', error.code, error.message);
|
|
995
|
+
toast.error(error.message);
|
|
964
996
|
}}
|
|
965
997
|
>
|
|
966
998
|
{children}
|
|
@@ -1006,7 +1038,10 @@ switch(e.code){
|
|
|
1006
1038
|
break
|
|
1007
1039
|
case "CONFIRM_ERROR":
|
|
1008
1040
|
alert('Failed to submit your comments')
|
|
1009
|
-
break
|
|
1041
|
+
break
|
|
1042
|
+
case "INSERT_ERROR":
|
|
1043
|
+
alert('Failed to insert your comment')
|
|
1044
|
+
break
|
|
1010
1045
|
default:
|
|
1011
1046
|
alert('An unknown error occured')
|
|
1012
1047
|
}
|
|
@@ -1176,6 +1211,13 @@ MIT © [Kendew Agency](https://github.com/Kendew-Agency)
|
|
|
1176
1211
|
|
|
1177
1212
|
A list if breaking changes that could impact the way you configured the package
|
|
1178
1213
|
|
|
1214
|
+
### 0.3.0
|
|
1215
|
+
- Added `projectId` prop to `CommentContextProvider`. When set, the project ID is attached to every new comment and passed as a second argument to the `onConfirm` callback. Update your `onConfirm` signature from `(comments) => ...` to `(comments, projectId?) => ...`.
|
|
1216
|
+
- `onError` is now a required prop on `CommentContextProvider`. If you previously omitted it, you must provide an error handler.
|
|
1217
|
+
- Added `InsertError` error class and `INSERT_ERROR` error code. The overlay now triggers `onError` instead of using `alert()` when a user tries to add a comment while editing or dismisses an empty comment.
|
|
1218
|
+
- Added `triggerError` method to the comment context (available via `useComments()`), allowing programmatic error triggering through the `onError` callback.
|
|
1219
|
+
- `CommentType` now includes an optional `projectId` field.
|
|
1220
|
+
|
|
1179
1221
|
### 0.2.0
|
|
1180
1222
|
- 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
1223
|
- `mode` was defined twice in props. It has been removed as a root prop and is now only part of the config.
|
|
@@ -12,7 +12,7 @@ declare class ConfirmError extends BaseError {
|
|
|
12
12
|
constructor(message?: string);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR";
|
|
15
|
+
type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR";
|
|
16
16
|
type KnownError = ConfirmError | ResolveError;
|
|
17
17
|
|
|
18
18
|
type CommentState = {
|
|
@@ -46,6 +46,11 @@ type CommentState = {
|
|
|
46
46
|
* Optional configuration for the comment layer
|
|
47
47
|
*/
|
|
48
48
|
config?: Config | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Attached a project ID to the current overlay
|
|
51
|
+
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
52
|
+
*/
|
|
53
|
+
projectId?: string | undefined;
|
|
49
54
|
};
|
|
50
55
|
/**
|
|
51
56
|
* The state of the comment overlay
|
|
@@ -97,8 +102,9 @@ type CommentOverlayProps = {
|
|
|
97
102
|
* Callback with all newly confirmed comments
|
|
98
103
|
*
|
|
99
104
|
* @param comments as the comments pushed by the user
|
|
105
|
+
* @param projectId as the project id if provided
|
|
100
106
|
*/
|
|
101
|
-
onConfirm: (comments: ConfirmedComment[]) => Promise<void>;
|
|
107
|
+
onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
|
|
102
108
|
/**
|
|
103
109
|
* Callback to handle resolved comments
|
|
104
110
|
*
|
|
@@ -110,11 +116,20 @@ type CommentOverlayProps = {
|
|
|
110
116
|
*
|
|
111
117
|
* @param error as the error that occurred
|
|
112
118
|
*/
|
|
113
|
-
onError
|
|
119
|
+
onError: (error: KnownError) => void;
|
|
114
120
|
/**
|
|
115
121
|
* Optional configuration for the comment layer
|
|
116
122
|
*/
|
|
117
123
|
config?: Config;
|
|
124
|
+
/**
|
|
125
|
+
* Attached a project ID to the current overlay
|
|
126
|
+
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* projectId: "proj_123456789"
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
projectId?: string;
|
|
118
133
|
};
|
|
119
134
|
interface RealtimeSubscription<T> {
|
|
120
135
|
subscribe(onUpdate: (data: T) => void): void;
|
|
@@ -183,6 +198,11 @@ type CommentType = {
|
|
|
183
198
|
* @description shows a box around the content a comment is tied to
|
|
184
199
|
*/
|
|
185
200
|
indicator?: Indicator | null;
|
|
201
|
+
/**
|
|
202
|
+
* The id of the project a comment is connected to
|
|
203
|
+
* @description useful for filtering comments by project
|
|
204
|
+
*/
|
|
205
|
+
projectId?: string | undefined;
|
|
186
206
|
};
|
|
187
207
|
type Status = "draft" | "published" | "resolving" | "resolved";
|
|
188
208
|
type ConfirmedStatus = Extract<Status, "published" | "resolved">;
|
|
@@ -248,6 +268,7 @@ type CommentContext = {
|
|
|
248
268
|
error: Error | DOMException | null;
|
|
249
269
|
}>;
|
|
250
270
|
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
271
|
+
triggerError: (error: KnownError) => void;
|
|
251
272
|
};
|
|
252
273
|
type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
|
|
253
274
|
status: T;
|
|
@@ -12,7 +12,7 @@ declare class ConfirmError extends BaseError {
|
|
|
12
12
|
constructor(message?: string);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR";
|
|
15
|
+
type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR";
|
|
16
16
|
type KnownError = ConfirmError | ResolveError;
|
|
17
17
|
|
|
18
18
|
type CommentState = {
|
|
@@ -46,6 +46,11 @@ type CommentState = {
|
|
|
46
46
|
* Optional configuration for the comment layer
|
|
47
47
|
*/
|
|
48
48
|
config?: Config | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Attached a project ID to the current overlay
|
|
51
|
+
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
52
|
+
*/
|
|
53
|
+
projectId?: string | undefined;
|
|
49
54
|
};
|
|
50
55
|
/**
|
|
51
56
|
* The state of the comment overlay
|
|
@@ -97,8 +102,9 @@ type CommentOverlayProps = {
|
|
|
97
102
|
* Callback with all newly confirmed comments
|
|
98
103
|
*
|
|
99
104
|
* @param comments as the comments pushed by the user
|
|
105
|
+
* @param projectId as the project id if provided
|
|
100
106
|
*/
|
|
101
|
-
onConfirm: (comments: ConfirmedComment[]) => Promise<void>;
|
|
107
|
+
onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
|
|
102
108
|
/**
|
|
103
109
|
* Callback to handle resolved comments
|
|
104
110
|
*
|
|
@@ -110,11 +116,20 @@ type CommentOverlayProps = {
|
|
|
110
116
|
*
|
|
111
117
|
* @param error as the error that occurred
|
|
112
118
|
*/
|
|
113
|
-
onError
|
|
119
|
+
onError: (error: KnownError) => void;
|
|
114
120
|
/**
|
|
115
121
|
* Optional configuration for the comment layer
|
|
116
122
|
*/
|
|
117
123
|
config?: Config;
|
|
124
|
+
/**
|
|
125
|
+
* Attached a project ID to the current overlay
|
|
126
|
+
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* projectId: "proj_123456789"
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
projectId?: string;
|
|
118
133
|
};
|
|
119
134
|
interface RealtimeSubscription<T> {
|
|
120
135
|
subscribe(onUpdate: (data: T) => void): void;
|
|
@@ -183,6 +198,11 @@ type CommentType = {
|
|
|
183
198
|
* @description shows a box around the content a comment is tied to
|
|
184
199
|
*/
|
|
185
200
|
indicator?: Indicator | null;
|
|
201
|
+
/**
|
|
202
|
+
* The id of the project a comment is connected to
|
|
203
|
+
* @description useful for filtering comments by project
|
|
204
|
+
*/
|
|
205
|
+
projectId?: string | undefined;
|
|
186
206
|
};
|
|
187
207
|
type Status = "draft" | "published" | "resolving" | "resolved";
|
|
188
208
|
type ConfirmedStatus = Extract<Status, "published" | "resolved">;
|
|
@@ -248,6 +268,7 @@ type CommentContext = {
|
|
|
248
268
|
error: Error | DOMException | null;
|
|
249
269
|
}>;
|
|
250
270
|
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
271
|
+
triggerError: (error: KnownError) => void;
|
|
251
272
|
};
|
|
252
273
|
type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
|
|
253
274
|
status: T;
|
package/dist/index.cjs
CHANGED
|
@@ -70,6 +70,11 @@ var BaseError = class extends Error {
|
|
|
70
70
|
this.status = status;
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
+
var InsertError = class extends BaseError {
|
|
74
|
+
constructor(message = "An error occured while inserting your comments") {
|
|
75
|
+
super(message, "INSERT_ERROR", 500);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
73
78
|
var ResolveError = class extends BaseError {
|
|
74
79
|
constructor(message = "An error occured while resolving your comments") {
|
|
75
80
|
super(message, "RESOLVE_ERROR", 500);
|
|
@@ -96,6 +101,7 @@ var commentReducer = (state, action) => {
|
|
|
96
101
|
...state.comments,
|
|
97
102
|
{
|
|
98
103
|
id: newId,
|
|
104
|
+
projectId: state.projectId,
|
|
99
105
|
user: state.currentUser,
|
|
100
106
|
position: {
|
|
101
107
|
x: action.position.x,
|
|
@@ -214,6 +220,7 @@ var CommentContextProvider = ({
|
|
|
214
220
|
hideResolving: false
|
|
215
221
|
}
|
|
216
222
|
},
|
|
223
|
+
projectId,
|
|
217
224
|
onError
|
|
218
225
|
}) => {
|
|
219
226
|
const [state, dispatch] = (0, import_react.useReducer)(commentReducer, {
|
|
@@ -221,7 +228,8 @@ var CommentContextProvider = ({
|
|
|
221
228
|
overlayState: initialOverlayState || "inactive",
|
|
222
229
|
currentUser,
|
|
223
230
|
focussedComment: null,
|
|
224
|
-
config
|
|
231
|
+
config,
|
|
232
|
+
projectId
|
|
225
233
|
});
|
|
226
234
|
(0, import_react.useEffect)(() => {
|
|
227
235
|
if (!subscription) return;
|
|
@@ -286,7 +294,8 @@ var CommentContextProvider = ({
|
|
|
286
294
|
draftComments.map((c) => ({
|
|
287
295
|
...c,
|
|
288
296
|
status: "published"
|
|
289
|
-
}))
|
|
297
|
+
})),
|
|
298
|
+
projectId
|
|
290
299
|
)
|
|
291
300
|
);
|
|
292
301
|
if (error) {
|
|
@@ -326,6 +335,11 @@ var CommentContextProvider = ({
|
|
|
326
335
|
const changeOverlayState = (state2) => {
|
|
327
336
|
dispatch({ type: "CHANGE_OVERLAYSTATE", to: state2 });
|
|
328
337
|
};
|
|
338
|
+
const triggerError = (error) => {
|
|
339
|
+
if (onError) {
|
|
340
|
+
onError(error);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
329
343
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
330
344
|
CommentContext.Provider,
|
|
331
345
|
{
|
|
@@ -348,7 +362,8 @@ var CommentContextProvider = ({
|
|
|
348
362
|
confirmComments,
|
|
349
363
|
currentUser,
|
|
350
364
|
resolveComments,
|
|
351
|
-
updateCommentVisibility
|
|
365
|
+
updateCommentVisibility,
|
|
366
|
+
triggerError
|
|
352
367
|
},
|
|
353
368
|
children
|
|
354
369
|
}
|
|
@@ -384,7 +399,8 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
384
399
|
registerComment,
|
|
385
400
|
focusOnComment,
|
|
386
401
|
getActiveComment,
|
|
387
|
-
changeOverlayState
|
|
402
|
+
changeOverlayState,
|
|
403
|
+
triggerError
|
|
388
404
|
} = useComments();
|
|
389
405
|
const [preview, setPreview] = (0, import_react2.useState)(null);
|
|
390
406
|
const startRef = (0, import_react2.useRef)(null);
|
|
@@ -392,8 +408,10 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
392
408
|
const overlayRef = (0, import_react2.useRef)(null);
|
|
393
409
|
const onPointerDown = (e) => {
|
|
394
410
|
if (overlayState === "editing") {
|
|
395
|
-
|
|
396
|
-
|
|
411
|
+
triggerError(
|
|
412
|
+
new InsertError(
|
|
413
|
+
"You are editing a comment, please finish editing the current comment first"
|
|
414
|
+
)
|
|
397
415
|
);
|
|
398
416
|
return;
|
|
399
417
|
}
|
|
@@ -468,6 +486,14 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
468
486
|
{
|
|
469
487
|
"data-comment-guard": true,
|
|
470
488
|
onClick: () => {
|
|
489
|
+
if (getActiveComment()?.content === "") {
|
|
490
|
+
triggerError(
|
|
491
|
+
new InsertError(
|
|
492
|
+
"Comment is empty, either delete the comment or add some content"
|
|
493
|
+
)
|
|
494
|
+
);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
471
497
|
focusOnComment(null);
|
|
472
498
|
changeOverlayState("idle");
|
|
473
499
|
},
|
|
@@ -490,8 +516,9 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
490
516
|
top: preview.y,
|
|
491
517
|
width: preview.width,
|
|
492
518
|
height: preview.height,
|
|
493
|
-
border: "
|
|
494
|
-
pointerEvents: "none"
|
|
519
|
+
border: "2px dashed black",
|
|
520
|
+
pointerEvents: "none",
|
|
521
|
+
zIndex: 1
|
|
495
522
|
}
|
|
496
523
|
}
|
|
497
524
|
),
|
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-
|
|
4
|
+
import { C as CommentType, a as CommentOverlayProps$1, b as CommentContext } from './comment.types-D2tC4rfE.cjs';
|
|
5
5
|
|
|
6
6
|
interface CommentOverlayProps extends HTMLProps<HTMLDivElement> {
|
|
7
7
|
children: ReactNode;
|
|
@@ -73,7 +73,7 @@ declare const Comment: {
|
|
|
73
73
|
*
|
|
74
74
|
* @param initialComments as the initial comments from the document
|
|
75
75
|
*/
|
|
76
|
-
declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, onConfirm, onResolve, currentUser, subscription, config, onError, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
|
|
76
|
+
declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, onConfirm, onResolve, currentUser, subscription, config, projectId, onError, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
|
|
77
77
|
declare const useComments: () => CommentContext;
|
|
78
78
|
|
|
79
79
|
type CommentScope = {
|
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-
|
|
4
|
+
import { C as CommentType, a as CommentOverlayProps$1, b as CommentContext } from './comment.types-D2tC4rfE.js';
|
|
5
5
|
|
|
6
6
|
interface CommentOverlayProps extends HTMLProps<HTMLDivElement> {
|
|
7
7
|
children: ReactNode;
|
|
@@ -73,7 +73,7 @@ declare const Comment: {
|
|
|
73
73
|
*
|
|
74
74
|
* @param initialComments as the initial comments from the document
|
|
75
75
|
*/
|
|
76
|
-
declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, onConfirm, onResolve, currentUser, subscription, config, onError, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
|
|
76
|
+
declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, onConfirm, onResolve, currentUser, subscription, config, projectId, onError, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
|
|
77
77
|
declare const useComments: () => CommentContext;
|
|
78
78
|
|
|
79
79
|
type CommentScope = {
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,11 @@ var BaseError = class extends Error {
|
|
|
28
28
|
this.status = status;
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
+
var InsertError = class extends BaseError {
|
|
32
|
+
constructor(message = "An error occured while inserting your comments") {
|
|
33
|
+
super(message, "INSERT_ERROR", 500);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
31
36
|
var ResolveError = class extends BaseError {
|
|
32
37
|
constructor(message = "An error occured while resolving your comments") {
|
|
33
38
|
super(message, "RESOLVE_ERROR", 500);
|
|
@@ -54,6 +59,7 @@ var commentReducer = (state, action) => {
|
|
|
54
59
|
...state.comments,
|
|
55
60
|
{
|
|
56
61
|
id: newId,
|
|
62
|
+
projectId: state.projectId,
|
|
57
63
|
user: state.currentUser,
|
|
58
64
|
position: {
|
|
59
65
|
x: action.position.x,
|
|
@@ -172,6 +178,7 @@ var CommentContextProvider = ({
|
|
|
172
178
|
hideResolving: false
|
|
173
179
|
}
|
|
174
180
|
},
|
|
181
|
+
projectId,
|
|
175
182
|
onError
|
|
176
183
|
}) => {
|
|
177
184
|
const [state, dispatch] = useReducer(commentReducer, {
|
|
@@ -179,7 +186,8 @@ var CommentContextProvider = ({
|
|
|
179
186
|
overlayState: initialOverlayState || "inactive",
|
|
180
187
|
currentUser,
|
|
181
188
|
focussedComment: null,
|
|
182
|
-
config
|
|
189
|
+
config,
|
|
190
|
+
projectId
|
|
183
191
|
});
|
|
184
192
|
useEffect(() => {
|
|
185
193
|
if (!subscription) return;
|
|
@@ -244,7 +252,8 @@ var CommentContextProvider = ({
|
|
|
244
252
|
draftComments.map((c) => ({
|
|
245
253
|
...c,
|
|
246
254
|
status: "published"
|
|
247
|
-
}))
|
|
255
|
+
})),
|
|
256
|
+
projectId
|
|
248
257
|
)
|
|
249
258
|
);
|
|
250
259
|
if (error) {
|
|
@@ -284,6 +293,11 @@ var CommentContextProvider = ({
|
|
|
284
293
|
const changeOverlayState = (state2) => {
|
|
285
294
|
dispatch({ type: "CHANGE_OVERLAYSTATE", to: state2 });
|
|
286
295
|
};
|
|
296
|
+
const triggerError = (error) => {
|
|
297
|
+
if (onError) {
|
|
298
|
+
onError(error);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
287
301
|
return /* @__PURE__ */ jsx(
|
|
288
302
|
CommentContext.Provider,
|
|
289
303
|
{
|
|
@@ -306,7 +320,8 @@ var CommentContextProvider = ({
|
|
|
306
320
|
confirmComments,
|
|
307
321
|
currentUser,
|
|
308
322
|
resolveComments,
|
|
309
|
-
updateCommentVisibility
|
|
323
|
+
updateCommentVisibility,
|
|
324
|
+
triggerError
|
|
310
325
|
},
|
|
311
326
|
children
|
|
312
327
|
}
|
|
@@ -342,7 +357,8 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
342
357
|
registerComment,
|
|
343
358
|
focusOnComment,
|
|
344
359
|
getActiveComment,
|
|
345
|
-
changeOverlayState
|
|
360
|
+
changeOverlayState,
|
|
361
|
+
triggerError
|
|
346
362
|
} = useComments();
|
|
347
363
|
const [preview, setPreview] = useState(null);
|
|
348
364
|
const startRef = useRef(null);
|
|
@@ -350,8 +366,10 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
350
366
|
const overlayRef = useRef(null);
|
|
351
367
|
const onPointerDown = (e) => {
|
|
352
368
|
if (overlayState === "editing") {
|
|
353
|
-
|
|
354
|
-
|
|
369
|
+
triggerError(
|
|
370
|
+
new InsertError(
|
|
371
|
+
"You are editing a comment, please finish editing the current comment first"
|
|
372
|
+
)
|
|
355
373
|
);
|
|
356
374
|
return;
|
|
357
375
|
}
|
|
@@ -426,6 +444,14 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
426
444
|
{
|
|
427
445
|
"data-comment-guard": true,
|
|
428
446
|
onClick: () => {
|
|
447
|
+
if (getActiveComment()?.content === "") {
|
|
448
|
+
triggerError(
|
|
449
|
+
new InsertError(
|
|
450
|
+
"Comment is empty, either delete the comment or add some content"
|
|
451
|
+
)
|
|
452
|
+
);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
429
455
|
focusOnComment(null);
|
|
430
456
|
changeOverlayState("idle");
|
|
431
457
|
},
|
|
@@ -448,8 +474,9 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
448
474
|
top: preview.y,
|
|
449
475
|
width: preview.width,
|
|
450
476
|
height: preview.height,
|
|
451
|
-
border: "
|
|
452
|
-
pointerEvents: "none"
|
|
477
|
+
border: "2px dashed black",
|
|
478
|
+
pointerEvents: "none",
|
|
479
|
+
zIndex: 1
|
|
453
480
|
}
|
|
454
481
|
}
|
|
455
482
|
),
|
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-
|
|
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-
|
|
1
|
+
import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-D2tC4rfE.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-D2tC4rfE.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-
|
|
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-
|
|
1
|
+
import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-D2tC4rfE.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-D2tC4rfE.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
/**
|