@kendew-agency/react-feedback-layer 0.4.0-rc.1 → 0.4.0-rc.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 +1 -0
- package/dist/index.cjs +12 -9
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1670,6 +1670,7 @@ A list if breaking changes that could impact the way you configured the package
|
|
|
1670
1670
|
- Breaking: removed `confirmComments`, `resolveComments`, `onConfirm`, array `onResolve`, `ConfirmComments`, `ResolveComments`, `onCommentsConfirmed` and `onCommentsResolved`. Removed the `resolving` comment status, `resolvingComments`, the `hideResolving` filter and the `ResolvingComment` renderer prop. Standalone use without a session provider is no longer possible. `initialComments` need a `sessionId` and a `locationId`.
|
|
1671
1671
|
- Added multi-location sessions. See [Sessions across multiple locations](#sessions-across-multiple-locations). Added the `locationId` prop on `CommentContextProvider` and `commentsBySession` on `useComments()`. `confirmSession` and `resolveSession` check the comments of all locations.
|
|
1672
1672
|
- Breaking: `locationId` is a required string on `CommentType` and `ConfirmedComment`. A comment is shown only when its `locationId` equals the provider's `locationId` and its `sessionId` equals the active session id. Existing stored comments need a `locationId`, or they are hidden and ignored by `confirmSession` and `resolveSession`. A provider without a `locationId` shows no comments, and `registerComment` reports an `AddError`.
|
|
1673
|
+
- Fixed `Comment.Content` showing a stale or typed draft. It now always renders the saved `comment.content`, so a draft comment shows no text in `Comment.Content` until it is confirmed. The draft of `Comment.Edit` resets when `comment.content` changes, and `defaultDraft` only seeds it on mount.
|
|
1673
1674
|
|
|
1674
1675
|
### 0.3.2
|
|
1675
1676
|
- Added `withPosition` prop to `Comment.Root`. It defaults to `true`, so existing behavior is unchanged. Set it to `false` to skip the absolute positioning styles (`position`, `top`, `left`), for example when rendering comments in a list.
|
package/dist/index.cjs
CHANGED
|
@@ -439,14 +439,13 @@ var SessionBridgeContext = (0, import_react3.createContext)(null);
|
|
|
439
439
|
var MAX_PROJECT_ID_LENGTH = 128;
|
|
440
440
|
var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
|
|
441
441
|
var pick = (value, fallback) => value !== void 0 ? value : fallback;
|
|
442
|
-
var createRefusal = (type, projectId, inFlight,
|
|
442
|
+
var createRefusal = (type, projectId, inFlight, hasCallback, user) => {
|
|
443
443
|
if (!user) return "user is required";
|
|
444
444
|
if (!isSessionType(type)) return "unknown session type";
|
|
445
445
|
if (!isValidProjectId(projectId)) {
|
|
446
446
|
return "projectId must be 1 to 128 characters";
|
|
447
447
|
}
|
|
448
448
|
if (inFlight === "creating") return "creation already in progress";
|
|
449
|
-
if (session?.status === "draft") return "draft session already exists";
|
|
450
449
|
if (!hasCallback) return "onCreateSession is not provided";
|
|
451
450
|
return null;
|
|
452
451
|
};
|
|
@@ -507,7 +506,6 @@ var FeedbackSessionProvider = ({
|
|
|
507
506
|
type,
|
|
508
507
|
sessionProjectId,
|
|
509
508
|
inFlightRef.current,
|
|
510
|
-
stateRef.current.session,
|
|
511
509
|
onCreateSession !== void 0,
|
|
512
510
|
user
|
|
513
511
|
);
|
|
@@ -1256,7 +1254,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
1256
1254
|
if (getActiveComment()?.content === "") {
|
|
1257
1255
|
triggerError(
|
|
1258
1256
|
new InsertError(
|
|
1259
|
-
"
|
|
1257
|
+
"A draft comment is still open. Either delete it or confirm it before adding a new comment"
|
|
1260
1258
|
)
|
|
1261
1259
|
);
|
|
1262
1260
|
return;
|
|
@@ -1376,6 +1374,11 @@ var CommentRoot = ({
|
|
|
1376
1374
|
const { getActiveComment } = useComments();
|
|
1377
1375
|
const isActive = getActiveComment()?.id === comment.id;
|
|
1378
1376
|
const [draft, setDraft] = (0, import_react6.useState)(defaultDraft ?? comment.content ?? "");
|
|
1377
|
+
const [prevContent, setPrevContent] = (0, import_react6.useState)(comment.content);
|
|
1378
|
+
if (prevContent !== comment.content) {
|
|
1379
|
+
setPrevContent(comment.content);
|
|
1380
|
+
setDraft(comment.content ?? "");
|
|
1381
|
+
}
|
|
1379
1382
|
const positionStyles = {
|
|
1380
1383
|
position: "absolute",
|
|
1381
1384
|
top: comment.position.y,
|
|
@@ -1427,9 +1430,9 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
1427
1430
|
);
|
|
1428
1431
|
};
|
|
1429
1432
|
var CommentContent = ({ asChild, ...rest }) => {
|
|
1430
|
-
const {
|
|
1433
|
+
const { comment } = useCommentScope();
|
|
1431
1434
|
const Comp = asChild ? import_react_slot2.Slot : "p";
|
|
1432
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Comp, { ...rest, children:
|
|
1435
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Comp, { ...rest, children: comment.content });
|
|
1433
1436
|
};
|
|
1434
1437
|
var CommentEdit = ({ asChild, ...rest }) => {
|
|
1435
1438
|
const { draft, setDraft } = useCommentScope();
|
|
@@ -1538,7 +1541,7 @@ var Comment = {
|
|
|
1538
1541
|
* The root component for a comment, must be used to wrap all other comment components.
|
|
1539
1542
|
*
|
|
1540
1543
|
* @param comment as the current comment from the comments array
|
|
1541
|
-
* @param defaultDraft as the optional initial value for the comment
|
|
1544
|
+
* @param defaultDraft as the optional initial value for the edit state of `Comment.Edit`. It only seeds the draft on mount and does not affect `Comment.Content`. The draft resets to `comment.content` whenever that changes
|
|
1542
1545
|
* @param withPosition as whether to inject positioning styles from the comment's position. Disable if you want to display the comment in a list. Defaults to true
|
|
1543
1546
|
*/
|
|
1544
1547
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
@@ -1551,9 +1554,9 @@ var Comment = {
|
|
|
1551
1554
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
1552
1555
|
Indicator: CommentIndicator,
|
|
1553
1556
|
/**
|
|
1554
|
-
* The comment's static
|
|
1557
|
+
* The comment's static saved content
|
|
1555
1558
|
*
|
|
1556
|
-
* @description Displays the comment
|
|
1559
|
+
* @description Displays the saved `comment.content` as a `<p>` tag. Text typed in `Comment.Edit` is not shown until it is confirmed, so a draft comment renders empty until then
|
|
1557
1560
|
* @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
|
|
1558
1561
|
*/
|
|
1559
1562
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
package/dist/index.d.cts
CHANGED
|
@@ -77,7 +77,7 @@ declare const Comment: {
|
|
|
77
77
|
* The root component for a comment, must be used to wrap all other comment components.
|
|
78
78
|
*
|
|
79
79
|
* @param comment as the current comment from the comments array
|
|
80
|
-
* @param defaultDraft as the optional initial value for the comment
|
|
80
|
+
* @param defaultDraft as the optional initial value for the edit state of `Comment.Edit`. It only seeds the draft on mount and does not affect `Comment.Content`. The draft resets to `comment.content` whenever that changes
|
|
81
81
|
* @param withPosition as whether to inject positioning styles from the comment's position. Disable if you want to display the comment in a list. Defaults to true
|
|
82
82
|
*/
|
|
83
83
|
Root: ({ comment, defaultDraft, withPosition, children, ...rest }: CommentRootProps) => react_jsx_runtime.JSX.Element;
|
|
@@ -88,9 +88,9 @@ declare const Comment: {
|
|
|
88
88
|
*/
|
|
89
89
|
Indicator: ({ ...rest }: CommentIndicatorProps) => react_jsx_runtime.JSX.Element | null;
|
|
90
90
|
/**
|
|
91
|
-
* The comment's static
|
|
91
|
+
* The comment's static saved content
|
|
92
92
|
*
|
|
93
|
-
* @description Displays the comment
|
|
93
|
+
* @description Displays the saved `comment.content` as a `<p>` tag. Text typed in `Comment.Edit` is not shown until it is confirmed, so a draft comment renders empty until then
|
|
94
94
|
* @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
|
|
95
95
|
*/
|
|
96
96
|
Content: ({ asChild, ...rest }: CommentContentProps) => react_jsx_runtime.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ declare const Comment: {
|
|
|
77
77
|
* The root component for a comment, must be used to wrap all other comment components.
|
|
78
78
|
*
|
|
79
79
|
* @param comment as the current comment from the comments array
|
|
80
|
-
* @param defaultDraft as the optional initial value for the comment
|
|
80
|
+
* @param defaultDraft as the optional initial value for the edit state of `Comment.Edit`. It only seeds the draft on mount and does not affect `Comment.Content`. The draft resets to `comment.content` whenever that changes
|
|
81
81
|
* @param withPosition as whether to inject positioning styles from the comment's position. Disable if you want to display the comment in a list. Defaults to true
|
|
82
82
|
*/
|
|
83
83
|
Root: ({ comment, defaultDraft, withPosition, children, ...rest }: CommentRootProps) => react_jsx_runtime.JSX.Element;
|
|
@@ -88,9 +88,9 @@ declare const Comment: {
|
|
|
88
88
|
*/
|
|
89
89
|
Indicator: ({ ...rest }: CommentIndicatorProps) => react_jsx_runtime.JSX.Element | null;
|
|
90
90
|
/**
|
|
91
|
-
* The comment's static
|
|
91
|
+
* The comment's static saved content
|
|
92
92
|
*
|
|
93
|
-
* @description Displays the comment
|
|
93
|
+
* @description Displays the saved `comment.content` as a `<p>` tag. Text typed in `Comment.Edit` is not shown until it is confirmed, so a draft comment renders empty until then
|
|
94
94
|
* @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
|
|
95
95
|
*/
|
|
96
96
|
Content: ({ asChild, ...rest }: CommentContentProps) => react_jsx_runtime.JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -407,14 +407,13 @@ var SessionBridgeContext = createContext(null);
|
|
|
407
407
|
var MAX_PROJECT_ID_LENGTH = 128;
|
|
408
408
|
var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
|
|
409
409
|
var pick = (value, fallback) => value !== void 0 ? value : fallback;
|
|
410
|
-
var createRefusal = (type, projectId, inFlight,
|
|
410
|
+
var createRefusal = (type, projectId, inFlight, hasCallback, user) => {
|
|
411
411
|
if (!user) return "user is required";
|
|
412
412
|
if (!isSessionType(type)) return "unknown session type";
|
|
413
413
|
if (!isValidProjectId(projectId)) {
|
|
414
414
|
return "projectId must be 1 to 128 characters";
|
|
415
415
|
}
|
|
416
416
|
if (inFlight === "creating") return "creation already in progress";
|
|
417
|
-
if (session?.status === "draft") return "draft session already exists";
|
|
418
417
|
if (!hasCallback) return "onCreateSession is not provided";
|
|
419
418
|
return null;
|
|
420
419
|
};
|
|
@@ -475,7 +474,6 @@ var FeedbackSessionProvider = ({
|
|
|
475
474
|
type,
|
|
476
475
|
sessionProjectId,
|
|
477
476
|
inFlightRef.current,
|
|
478
|
-
stateRef.current.session,
|
|
479
477
|
onCreateSession !== void 0,
|
|
480
478
|
user
|
|
481
479
|
);
|
|
@@ -1224,7 +1222,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
1224
1222
|
if (getActiveComment()?.content === "") {
|
|
1225
1223
|
triggerError(
|
|
1226
1224
|
new InsertError(
|
|
1227
|
-
"
|
|
1225
|
+
"A draft comment is still open. Either delete it or confirm it before adding a new comment"
|
|
1228
1226
|
)
|
|
1229
1227
|
);
|
|
1230
1228
|
return;
|
|
@@ -1346,6 +1344,11 @@ var CommentRoot = ({
|
|
|
1346
1344
|
const { getActiveComment } = useComments();
|
|
1347
1345
|
const isActive = getActiveComment()?.id === comment.id;
|
|
1348
1346
|
const [draft, setDraft] = useState2(defaultDraft ?? comment.content ?? "");
|
|
1347
|
+
const [prevContent, setPrevContent] = useState2(comment.content);
|
|
1348
|
+
if (prevContent !== comment.content) {
|
|
1349
|
+
setPrevContent(comment.content);
|
|
1350
|
+
setDraft(comment.content ?? "");
|
|
1351
|
+
}
|
|
1349
1352
|
const positionStyles = {
|
|
1350
1353
|
position: "absolute",
|
|
1351
1354
|
top: comment.position.y,
|
|
@@ -1397,9 +1400,9 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
1397
1400
|
);
|
|
1398
1401
|
};
|
|
1399
1402
|
var CommentContent = ({ asChild, ...rest }) => {
|
|
1400
|
-
const {
|
|
1403
|
+
const { comment } = useCommentScope();
|
|
1401
1404
|
const Comp = asChild ? Slot2 : "p";
|
|
1402
|
-
return /* @__PURE__ */ jsx6(Comp, { ...rest, children:
|
|
1405
|
+
return /* @__PURE__ */ jsx6(Comp, { ...rest, children: comment.content });
|
|
1403
1406
|
};
|
|
1404
1407
|
var CommentEdit = ({ asChild, ...rest }) => {
|
|
1405
1408
|
const { draft, setDraft } = useCommentScope();
|
|
@@ -1508,7 +1511,7 @@ var Comment = {
|
|
|
1508
1511
|
* The root component for a comment, must be used to wrap all other comment components.
|
|
1509
1512
|
*
|
|
1510
1513
|
* @param comment as the current comment from the comments array
|
|
1511
|
-
* @param defaultDraft as the optional initial value for the comment
|
|
1514
|
+
* @param defaultDraft as the optional initial value for the edit state of `Comment.Edit`. It only seeds the draft on mount and does not affect `Comment.Content`. The draft resets to `comment.content` whenever that changes
|
|
1512
1515
|
* @param withPosition as whether to inject positioning styles from the comment's position. Disable if you want to display the comment in a list. Defaults to true
|
|
1513
1516
|
*/
|
|
1514
1517
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
@@ -1521,9 +1524,9 @@ var Comment = {
|
|
|
1521
1524
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
1522
1525
|
Indicator: CommentIndicator,
|
|
1523
1526
|
/**
|
|
1524
|
-
* The comment's static
|
|
1527
|
+
* The comment's static saved content
|
|
1525
1528
|
*
|
|
1526
|
-
* @description Displays the comment
|
|
1529
|
+
* @description Displays the saved `comment.content` as a `<p>` tag. Text typed in `Comment.Edit` is not shown until it is confirmed, so a draft comment renders empty until then
|
|
1527
1530
|
* @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
|
|
1528
1531
|
*/
|
|
1529
1532
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
package/package.json
CHANGED