@kendew-agency/react-feedback-layer 0.1.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/LICENSE +21 -0
- package/README.md +1156 -0
- package/dist/comment.types-B7xO89Wt.d.cts +240 -0
- package/dist/comment.types-B7xO89Wt.d.ts +240 -0
- package/dist/index.cjs +756 -0
- package/dist/index.d.cts +87 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +712 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +39 -0
- package/dist/types.d.ts +39 -0
- package/dist/types.js +0 -0
- package/package.json +83 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type CommentState = {
|
|
4
|
+
/**
|
|
5
|
+
* All confirmed comments
|
|
6
|
+
* @description This is used to track all confirmed comments
|
|
7
|
+
*/
|
|
8
|
+
comments: CommentType[];
|
|
9
|
+
/**
|
|
10
|
+
* The state of the comment overlay
|
|
11
|
+
* @description This value is used to track the state of the comment overlay
|
|
12
|
+
* @see CommentOverlayState
|
|
13
|
+
*/
|
|
14
|
+
overlayState: CommentOverlayState;
|
|
15
|
+
/**
|
|
16
|
+
* The current loged in user.
|
|
17
|
+
* @description This data will be included when a user adds a comment
|
|
18
|
+
*/
|
|
19
|
+
currentUser: User | null;
|
|
20
|
+
/**
|
|
21
|
+
* Track the focussed comment when editing or adding a comment
|
|
22
|
+
* The comment key will be stored in this state
|
|
23
|
+
*/
|
|
24
|
+
focussedComment: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Any error that occurs during comment operations
|
|
27
|
+
* The value can be used to display an error message to the user
|
|
28
|
+
*/
|
|
29
|
+
error?: Error;
|
|
30
|
+
/**
|
|
31
|
+
* Optional configuration for the comment layer
|
|
32
|
+
*/
|
|
33
|
+
config?: Config | undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The state of the comment overlay
|
|
37
|
+
* @description This is used to track the state of the comment overlay
|
|
38
|
+
*/
|
|
39
|
+
type CommentOverlayState = "idle" | "editing" | "saving" | "error" | "resolving" | "inactive";
|
|
40
|
+
type CommentVisibility = {
|
|
41
|
+
/**
|
|
42
|
+
* Hide comments that are marked as resolved
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
hideResolved?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Hide comments that are being resolved
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
hideResolving?: boolean;
|
|
51
|
+
};
|
|
52
|
+
type CommentOverlayProps = {
|
|
53
|
+
/**
|
|
54
|
+
* Initial comments present when opening the comment overlay
|
|
55
|
+
* @description These comments usually come from your database
|
|
56
|
+
*/
|
|
57
|
+
initialComments?: ConfirmedComment[];
|
|
58
|
+
/**
|
|
59
|
+
* The current user
|
|
60
|
+
*
|
|
61
|
+
* @description This is used to identify the user in your database. If you can not provide a user, comments will be added anonymously
|
|
62
|
+
* @default null
|
|
63
|
+
*/
|
|
64
|
+
currentUser: User | null;
|
|
65
|
+
/**
|
|
66
|
+
* The children of the comment overlay
|
|
67
|
+
* @description This is where the comments will be rendered
|
|
68
|
+
*/
|
|
69
|
+
children: ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
* The state of the overlay on initial render
|
|
72
|
+
* @default "inactive"
|
|
73
|
+
*/
|
|
74
|
+
initialOverlayState?: CommentOverlayState;
|
|
75
|
+
/**
|
|
76
|
+
* Realtime subscription if supported by you DB
|
|
77
|
+
*/
|
|
78
|
+
subscription?: Suscription;
|
|
79
|
+
mode?: "onConfirm";
|
|
80
|
+
/**
|
|
81
|
+
* Callback with all newly confirmed comments
|
|
82
|
+
*
|
|
83
|
+
* @param comments as the comments pushed by the user
|
|
84
|
+
*/
|
|
85
|
+
onConfirm: (comments: ConfirmedComment[]) => Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Callback to handle resolved comments
|
|
88
|
+
*
|
|
89
|
+
* @param comments as the comments that are marked as resolved
|
|
90
|
+
*/
|
|
91
|
+
onResolve: (comments: ConfirmedComment[]) => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Callback to handle errors
|
|
94
|
+
*
|
|
95
|
+
* @param error as the error that occurred
|
|
96
|
+
*/
|
|
97
|
+
onError?: (error: Error) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Optional configuration for the comment layer
|
|
100
|
+
*/
|
|
101
|
+
config?: Config;
|
|
102
|
+
};
|
|
103
|
+
type Suscription = {
|
|
104
|
+
subscribe: (update: unknown) => void;
|
|
105
|
+
unsubscribe: () => void;
|
|
106
|
+
};
|
|
107
|
+
type Config = {
|
|
108
|
+
/**
|
|
109
|
+
* A custom prefix for the comment ids
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* idPrefix: "proj_a_" // Results in id="proj_a_a096e551-9822-4d10-876c-70651be36c70"
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
idPrefix?: string;
|
|
116
|
+
/**
|
|
117
|
+
* The visibility of the comment indicator
|
|
118
|
+
* @default 'always'
|
|
119
|
+
*/
|
|
120
|
+
indicatorVisibility?: "always" | "active";
|
|
121
|
+
/**
|
|
122
|
+
* Mode of the comment overlay
|
|
123
|
+
* @default "onConfirm"
|
|
124
|
+
*/
|
|
125
|
+
mode?: "onConfirm";
|
|
126
|
+
/**
|
|
127
|
+
* The visibility of the different type of comments
|
|
128
|
+
* @description This is used to temporarily hide comments of a certain type if a user whishes a cleaner view
|
|
129
|
+
* @see CommentVisibility
|
|
130
|
+
*/
|
|
131
|
+
commentVisibility?: CommentVisibility;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type CommentType = {
|
|
135
|
+
/**
|
|
136
|
+
* The unique identifier of a comment
|
|
137
|
+
*/
|
|
138
|
+
id: string;
|
|
139
|
+
/**
|
|
140
|
+
* The postion of a comment
|
|
141
|
+
* @description the postion holds both the x and y coordinates of a comment
|
|
142
|
+
*/
|
|
143
|
+
position: Position;
|
|
144
|
+
/**
|
|
145
|
+
* The content of a comment
|
|
146
|
+
*/
|
|
147
|
+
content: string;
|
|
148
|
+
/**
|
|
149
|
+
* The user who created the comment
|
|
150
|
+
*/
|
|
151
|
+
user: User | null;
|
|
152
|
+
/**
|
|
153
|
+
* The date when the comment was created
|
|
154
|
+
*/
|
|
155
|
+
createdAt: Date;
|
|
156
|
+
/**
|
|
157
|
+
* The date when the comment was resolved
|
|
158
|
+
*/
|
|
159
|
+
resolvedAt?: Date;
|
|
160
|
+
/**
|
|
161
|
+
* The state of a comment tracking what the comment is currently doing
|
|
162
|
+
* @description This value will be omitted when sending the comment to your DB
|
|
163
|
+
*/
|
|
164
|
+
status: Status;
|
|
165
|
+
/**
|
|
166
|
+
* An indicator to show the user where the comment is located
|
|
167
|
+
* @description shows a box around the content a comment is tied to
|
|
168
|
+
*/
|
|
169
|
+
indicator?: Indicator | null;
|
|
170
|
+
};
|
|
171
|
+
type Status = "draft" | "published" | "resolving" | "resolved";
|
|
172
|
+
type ConfirmedStatus = Extract<Status, "published" | "resolved">;
|
|
173
|
+
type ConfirmedComment = Omit<CommentType, "status"> & {
|
|
174
|
+
status: ConfirmedStatus;
|
|
175
|
+
};
|
|
176
|
+
type Indicator = {
|
|
177
|
+
/**
|
|
178
|
+
* The width of the indicator
|
|
179
|
+
*/
|
|
180
|
+
width: number;
|
|
181
|
+
/**
|
|
182
|
+
* The height of the indicator
|
|
183
|
+
*/
|
|
184
|
+
height: number;
|
|
185
|
+
};
|
|
186
|
+
type Position = {
|
|
187
|
+
/**
|
|
188
|
+
* The comment position on the x axis
|
|
189
|
+
*/
|
|
190
|
+
x: number;
|
|
191
|
+
/**
|
|
192
|
+
* The comment position on the y axis
|
|
193
|
+
*/
|
|
194
|
+
y: number;
|
|
195
|
+
};
|
|
196
|
+
type User = {
|
|
197
|
+
/**
|
|
198
|
+
* The user ID. This is used to identify the user in your database.
|
|
199
|
+
* @description This is optional, but it is recommended to establish a connection to the user in your DB.
|
|
200
|
+
*/
|
|
201
|
+
id?: string;
|
|
202
|
+
/**
|
|
203
|
+
* The name of the user. This is used to display the user's name in the UI.
|
|
204
|
+
*/
|
|
205
|
+
name: string;
|
|
206
|
+
/**
|
|
207
|
+
* The avatar of the user if supported. This will fall back to user initials.
|
|
208
|
+
*/
|
|
209
|
+
avatar?: string;
|
|
210
|
+
};
|
|
211
|
+
type CommentContext = {
|
|
212
|
+
draftComments: CommentWithStatus<"draft">[];
|
|
213
|
+
comments: CommentWithStatus<"published">[];
|
|
214
|
+
resolvingComments: CommentWithStatus<"resolving">[];
|
|
215
|
+
resolvedComments: CommentWithStatus<"resolved">[];
|
|
216
|
+
allComments: CommentType[];
|
|
217
|
+
config: Config | undefined;
|
|
218
|
+
toggleResolvingComment: (id: string) => void;
|
|
219
|
+
changeOverlayState: (state: CommentOverlayState) => void;
|
|
220
|
+
overlayState: CommentOverlayState;
|
|
221
|
+
updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
|
|
222
|
+
deleteComment: (id: string) => void;
|
|
223
|
+
focusOnComment: (id: string | null) => void;
|
|
224
|
+
registerComment: (position: Position, indicatorPosition?: Indicator) => void;
|
|
225
|
+
getActiveComment: () => CommentType | undefined;
|
|
226
|
+
toggleOverlay: () => void;
|
|
227
|
+
confirmComments: () => Promise<{
|
|
228
|
+
error: Error | DOMException | null;
|
|
229
|
+
}>;
|
|
230
|
+
currentUser: User | null;
|
|
231
|
+
resolveComments: () => Promise<{
|
|
232
|
+
error: Error | DOMException | null;
|
|
233
|
+
}>;
|
|
234
|
+
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
235
|
+
};
|
|
236
|
+
type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
|
|
237
|
+
status: T;
|
|
238
|
+
};
|
|
239
|
+
|
|
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 };
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type CommentState = {
|
|
4
|
+
/**
|
|
5
|
+
* All confirmed comments
|
|
6
|
+
* @description This is used to track all confirmed comments
|
|
7
|
+
*/
|
|
8
|
+
comments: CommentType[];
|
|
9
|
+
/**
|
|
10
|
+
* The state of the comment overlay
|
|
11
|
+
* @description This value is used to track the state of the comment overlay
|
|
12
|
+
* @see CommentOverlayState
|
|
13
|
+
*/
|
|
14
|
+
overlayState: CommentOverlayState;
|
|
15
|
+
/**
|
|
16
|
+
* The current loged in user.
|
|
17
|
+
* @description This data will be included when a user adds a comment
|
|
18
|
+
*/
|
|
19
|
+
currentUser: User | null;
|
|
20
|
+
/**
|
|
21
|
+
* Track the focussed comment when editing or adding a comment
|
|
22
|
+
* The comment key will be stored in this state
|
|
23
|
+
*/
|
|
24
|
+
focussedComment: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Any error that occurs during comment operations
|
|
27
|
+
* The value can be used to display an error message to the user
|
|
28
|
+
*/
|
|
29
|
+
error?: Error;
|
|
30
|
+
/**
|
|
31
|
+
* Optional configuration for the comment layer
|
|
32
|
+
*/
|
|
33
|
+
config?: Config | undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The state of the comment overlay
|
|
37
|
+
* @description This is used to track the state of the comment overlay
|
|
38
|
+
*/
|
|
39
|
+
type CommentOverlayState = "idle" | "editing" | "saving" | "error" | "resolving" | "inactive";
|
|
40
|
+
type CommentVisibility = {
|
|
41
|
+
/**
|
|
42
|
+
* Hide comments that are marked as resolved
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
hideResolved?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Hide comments that are being resolved
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
hideResolving?: boolean;
|
|
51
|
+
};
|
|
52
|
+
type CommentOverlayProps = {
|
|
53
|
+
/**
|
|
54
|
+
* Initial comments present when opening the comment overlay
|
|
55
|
+
* @description These comments usually come from your database
|
|
56
|
+
*/
|
|
57
|
+
initialComments?: ConfirmedComment[];
|
|
58
|
+
/**
|
|
59
|
+
* The current user
|
|
60
|
+
*
|
|
61
|
+
* @description This is used to identify the user in your database. If you can not provide a user, comments will be added anonymously
|
|
62
|
+
* @default null
|
|
63
|
+
*/
|
|
64
|
+
currentUser: User | null;
|
|
65
|
+
/**
|
|
66
|
+
* The children of the comment overlay
|
|
67
|
+
* @description This is where the comments will be rendered
|
|
68
|
+
*/
|
|
69
|
+
children: ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
* The state of the overlay on initial render
|
|
72
|
+
* @default "inactive"
|
|
73
|
+
*/
|
|
74
|
+
initialOverlayState?: CommentOverlayState;
|
|
75
|
+
/**
|
|
76
|
+
* Realtime subscription if supported by you DB
|
|
77
|
+
*/
|
|
78
|
+
subscription?: Suscription;
|
|
79
|
+
mode?: "onConfirm";
|
|
80
|
+
/**
|
|
81
|
+
* Callback with all newly confirmed comments
|
|
82
|
+
*
|
|
83
|
+
* @param comments as the comments pushed by the user
|
|
84
|
+
*/
|
|
85
|
+
onConfirm: (comments: ConfirmedComment[]) => Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Callback to handle resolved comments
|
|
88
|
+
*
|
|
89
|
+
* @param comments as the comments that are marked as resolved
|
|
90
|
+
*/
|
|
91
|
+
onResolve: (comments: ConfirmedComment[]) => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Callback to handle errors
|
|
94
|
+
*
|
|
95
|
+
* @param error as the error that occurred
|
|
96
|
+
*/
|
|
97
|
+
onError?: (error: Error) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Optional configuration for the comment layer
|
|
100
|
+
*/
|
|
101
|
+
config?: Config;
|
|
102
|
+
};
|
|
103
|
+
type Suscription = {
|
|
104
|
+
subscribe: (update: unknown) => void;
|
|
105
|
+
unsubscribe: () => void;
|
|
106
|
+
};
|
|
107
|
+
type Config = {
|
|
108
|
+
/**
|
|
109
|
+
* A custom prefix for the comment ids
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* idPrefix: "proj_a_" // Results in id="proj_a_a096e551-9822-4d10-876c-70651be36c70"
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
idPrefix?: string;
|
|
116
|
+
/**
|
|
117
|
+
* The visibility of the comment indicator
|
|
118
|
+
* @default 'always'
|
|
119
|
+
*/
|
|
120
|
+
indicatorVisibility?: "always" | "active";
|
|
121
|
+
/**
|
|
122
|
+
* Mode of the comment overlay
|
|
123
|
+
* @default "onConfirm"
|
|
124
|
+
*/
|
|
125
|
+
mode?: "onConfirm";
|
|
126
|
+
/**
|
|
127
|
+
* The visibility of the different type of comments
|
|
128
|
+
* @description This is used to temporarily hide comments of a certain type if a user whishes a cleaner view
|
|
129
|
+
* @see CommentVisibility
|
|
130
|
+
*/
|
|
131
|
+
commentVisibility?: CommentVisibility;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type CommentType = {
|
|
135
|
+
/**
|
|
136
|
+
* The unique identifier of a comment
|
|
137
|
+
*/
|
|
138
|
+
id: string;
|
|
139
|
+
/**
|
|
140
|
+
* The postion of a comment
|
|
141
|
+
* @description the postion holds both the x and y coordinates of a comment
|
|
142
|
+
*/
|
|
143
|
+
position: Position;
|
|
144
|
+
/**
|
|
145
|
+
* The content of a comment
|
|
146
|
+
*/
|
|
147
|
+
content: string;
|
|
148
|
+
/**
|
|
149
|
+
* The user who created the comment
|
|
150
|
+
*/
|
|
151
|
+
user: User | null;
|
|
152
|
+
/**
|
|
153
|
+
* The date when the comment was created
|
|
154
|
+
*/
|
|
155
|
+
createdAt: Date;
|
|
156
|
+
/**
|
|
157
|
+
* The date when the comment was resolved
|
|
158
|
+
*/
|
|
159
|
+
resolvedAt?: Date;
|
|
160
|
+
/**
|
|
161
|
+
* The state of a comment tracking what the comment is currently doing
|
|
162
|
+
* @description This value will be omitted when sending the comment to your DB
|
|
163
|
+
*/
|
|
164
|
+
status: Status;
|
|
165
|
+
/**
|
|
166
|
+
* An indicator to show the user where the comment is located
|
|
167
|
+
* @description shows a box around the content a comment is tied to
|
|
168
|
+
*/
|
|
169
|
+
indicator?: Indicator | null;
|
|
170
|
+
};
|
|
171
|
+
type Status = "draft" | "published" | "resolving" | "resolved";
|
|
172
|
+
type ConfirmedStatus = Extract<Status, "published" | "resolved">;
|
|
173
|
+
type ConfirmedComment = Omit<CommentType, "status"> & {
|
|
174
|
+
status: ConfirmedStatus;
|
|
175
|
+
};
|
|
176
|
+
type Indicator = {
|
|
177
|
+
/**
|
|
178
|
+
* The width of the indicator
|
|
179
|
+
*/
|
|
180
|
+
width: number;
|
|
181
|
+
/**
|
|
182
|
+
* The height of the indicator
|
|
183
|
+
*/
|
|
184
|
+
height: number;
|
|
185
|
+
};
|
|
186
|
+
type Position = {
|
|
187
|
+
/**
|
|
188
|
+
* The comment position on the x axis
|
|
189
|
+
*/
|
|
190
|
+
x: number;
|
|
191
|
+
/**
|
|
192
|
+
* The comment position on the y axis
|
|
193
|
+
*/
|
|
194
|
+
y: number;
|
|
195
|
+
};
|
|
196
|
+
type User = {
|
|
197
|
+
/**
|
|
198
|
+
* The user ID. This is used to identify the user in your database.
|
|
199
|
+
* @description This is optional, but it is recommended to establish a connection to the user in your DB.
|
|
200
|
+
*/
|
|
201
|
+
id?: string;
|
|
202
|
+
/**
|
|
203
|
+
* The name of the user. This is used to display the user's name in the UI.
|
|
204
|
+
*/
|
|
205
|
+
name: string;
|
|
206
|
+
/**
|
|
207
|
+
* The avatar of the user if supported. This will fall back to user initials.
|
|
208
|
+
*/
|
|
209
|
+
avatar?: string;
|
|
210
|
+
};
|
|
211
|
+
type CommentContext = {
|
|
212
|
+
draftComments: CommentWithStatus<"draft">[];
|
|
213
|
+
comments: CommentWithStatus<"published">[];
|
|
214
|
+
resolvingComments: CommentWithStatus<"resolving">[];
|
|
215
|
+
resolvedComments: CommentWithStatus<"resolved">[];
|
|
216
|
+
allComments: CommentType[];
|
|
217
|
+
config: Config | undefined;
|
|
218
|
+
toggleResolvingComment: (id: string) => void;
|
|
219
|
+
changeOverlayState: (state: CommentOverlayState) => void;
|
|
220
|
+
overlayState: CommentOverlayState;
|
|
221
|
+
updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
|
|
222
|
+
deleteComment: (id: string) => void;
|
|
223
|
+
focusOnComment: (id: string | null) => void;
|
|
224
|
+
registerComment: (position: Position, indicatorPosition?: Indicator) => void;
|
|
225
|
+
getActiveComment: () => CommentType | undefined;
|
|
226
|
+
toggleOverlay: () => void;
|
|
227
|
+
confirmComments: () => Promise<{
|
|
228
|
+
error: Error | DOMException | null;
|
|
229
|
+
}>;
|
|
230
|
+
currentUser: User | null;
|
|
231
|
+
resolveComments: () => Promise<{
|
|
232
|
+
error: Error | DOMException | null;
|
|
233
|
+
}>;
|
|
234
|
+
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
235
|
+
};
|
|
236
|
+
type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
|
|
237
|
+
status: T;
|
|
238
|
+
};
|
|
239
|
+
|
|
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 };
|