@edifice.io/react 2.0.0-develop-pedago.20250107165218 → 2.0.0-develop-pedago.20250108121012

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.
@@ -20,7 +20,7 @@ const Root = /* @__PURE__ */ forwardRef((props, ref) => {
20
20
  scrollable = !1,
21
21
  focusId,
22
22
  children
23
- } = props, ariaLabelId = `aria_label_${id}`, ariaDescriptionId = `aria_desc_${id}`, modalRef = useClickOutside(onModalClose), trapRef = useTrapFocus();
23
+ } = props, ariaLabelId = `aria_label_${id}`, ariaDescriptionId = `aria_desc_${id}`, modalRef = useClickOutside(onModalClose), trapRef = useTrapFocus(isOpen);
24
24
  useKeyPress(onModalClose, ["Escape"]), useEffect(() => {
25
25
  if (isOpen && (document.body.style.overflow = "hidden", focusId)) {
26
26
  const elem = document.getElementById(focusId);
@@ -1 +1 @@
1
- export default function useTrapFocus(): import('react').MutableRefObject<HTMLElement | null>;
1
+ export default function useTrapFocus(isActive?: boolean): import('react').MutableRefObject<HTMLElement | null>;
@@ -1,7 +1,8 @@
1
1
  import { useRef, useEffect } from "react";
2
- function useTrapFocus() {
2
+ function useTrapFocus(isActive) {
3
3
  const ref = useRef(null), focusableElements = 'button:not([disabled]), [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
4
4
  return useEffect(() => {
5
+ if (!isActive) return;
5
6
  const node = ref.current, firstFocusableElement = node.querySelectorAll(focusableElements)[0], focusableContent = node.querySelectorAll(focusableElements), lastFocusableElement = ref && (focusableContent == null ? void 0 : focusableContent[focusableContent.length - 1]), handleKeydown = (event) => {
6
7
  event.key === "Tab" && (event.shiftKey ? document.activeElement === firstFocusableElement && (lastFocusableElement.focus(), event.preventDefault()) : document.activeElement === lastFocusableElement && (firstFocusableElement.focus(), event.preventDefault()));
7
8
  };
@@ -9,7 +10,7 @@ function useTrapFocus() {
9
10
  return node.addEventListener("keydown", handleKeydown), () => {
10
11
  node.removeEventListener("keydown", handleKeydown);
11
12
  };
12
- }, []), ref;
13
+ }, [isActive]), ref;
13
14
  }
14
15
  export {
15
16
  useTrapFocus as default
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { useState, Suspense, lazy } from "react";
3
3
  import { useTranslation } from "react-i18next";
4
4
  import SvgIconSave from "../../icons/components/IconSave.js";
5
5
  import { useAutosizeTextarea } from "../hooks/useAutosizeTextarea.js";
@@ -10,7 +10,8 @@ import { CommentDate } from "./CommentDate.js";
10
10
  import { CommentTitle } from "./CommentTitle.js";
11
11
  import { TextCounter } from "./TextCounter.js";
12
12
  import Button from "../../../components/Button/Button.js";
13
- const Comment = ({
13
+ import LoadingScreen from "../../../components/LoadingScreen/LoadingScreen.js";
14
+ const DeleteModal = /* @__PURE__ */ lazy(() => import("./DeleteModal.js")), Comment = ({
14
15
  comment,
15
16
  userId,
16
17
  profile
@@ -22,12 +23,13 @@ const Comment = ({
22
23
  createdAt,
23
24
  updatedAt,
24
25
  comment: content
25
- } = comment, [ref, onFocus, resizeTextarea] = useAutosizeTextarea(!0), {
26
+ } = comment, [ref, onFocus, resizeTextarea] = useAutosizeTextarea(!0), [isDeleteModalOpen, setIsDeleteModalOpen] = useState(!1), {
26
27
  t
27
28
  } = useTranslation(), {
28
29
  editCommentId,
29
30
  options,
30
31
  type,
32
+ userRights,
31
33
  handleDeleteComment: onDeleteComment,
32
34
  handleModifyComment,
33
35
  handleReset,
@@ -57,14 +59,15 @@ const Comment = ({
57
59
  ] })
58
60
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
59
61
  /* @__PURE__ */ jsx("div", { className: "mt-8 mb-4", children: content }),
60
- userId === authorId && type === "edit" && /* @__PURE__ */ jsxs("div", { className: "ms-n8", children: [
61
- /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", size: "sm", onClick: () => {
62
+ type === "edit" && /* @__PURE__ */ jsxs("div", { className: "ms-n8", children: [
63
+ userId === authorId && /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", size: "sm", onClick: () => {
62
64
  handleModifyComment(comment.id), setValue(content);
63
65
  }, children: t("comment.edit") }),
64
- /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", size: "sm", onClick: () => onDeleteComment(id), children: t("comment.remove") })
66
+ (userId === authorId || (userRights == null ? void 0 : userRights.manager)) && /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", size: "sm", onClick: () => setIsDeleteModalOpen(!0), children: t("comment.remove") })
65
67
  ] })
66
68
  ] })
67
- ] })
69
+ ] }),
70
+ /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(LoadingScreen, { position: !1 }), children: isDeleteModalOpen && /* @__PURE__ */ jsx(DeleteModal, { isOpen: isDeleteModalOpen, onCancel: () => setIsDeleteModalOpen(!1), onSuccess: () => onDeleteComment(id) }) })
68
71
  ] }, id);
69
72
  };
70
73
  export {
@@ -0,0 +1,7 @@
1
+ interface DeleteModalProps {
2
+ isOpen: boolean;
3
+ onCancel: () => void;
4
+ onSuccess: () => void;
5
+ }
6
+ export declare const DeleteModal: ({ isOpen, onCancel, onSuccess, }: DeleteModalProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default DeleteModal;
@@ -0,0 +1,19 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import Modal from "../../../components/Modal/Modal.js";
3
+ import Button from "../../../components/Button/Button.js";
4
+ const DeleteModal = ({
5
+ isOpen,
6
+ onCancel,
7
+ onSuccess
8
+ }) => /* @__PURE__ */ jsxs(Modal, { isOpen, onModalClose: onCancel, id: "delete-comment-modal", children: [
9
+ /* @__PURE__ */ jsx(Modal.Header, { onModalClose: onCancel, children: "Suppression de commentaire" }),
10
+ /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx("p", { children: "Voulez-vous vraiment supprimer ce commentaire ?" }) }),
11
+ /* @__PURE__ */ jsxs(Modal.Footer, { children: [
12
+ /* @__PURE__ */ jsx(Button, { color: "tertiary", onClick: onCancel, type: "button", variant: "ghost", children: "Annuler" }),
13
+ /* @__PURE__ */ jsx(Button, { color: "danger", onClick: onSuccess, type: "button", variant: "filled", children: "Supprimer le commentaire" })
14
+ ] })
15
+ ] });
16
+ export {
17
+ DeleteModal,
18
+ DeleteModal as default
19
+ };
@@ -1,3 +1,4 @@
1
+ import { RightRole } from '@edifice.io/client';
1
2
  import { CommentOptions, CommentProps, CommentType, UserProfileResult } from '../types';
2
3
  export declare const CommentContext: import('react').Context<{
3
4
  comments: CommentProps[] | undefined;
@@ -6,6 +7,7 @@ export declare const CommentContext: import('react').Context<{
6
7
  profiles: (UserProfileResult | undefined)[];
7
8
  options: Partial<CommentOptions>;
8
9
  type: CommentType;
10
+ userRights?: Record<RightRole, boolean>;
9
11
  setEditCommentId: (value: string | null) => void;
10
12
  handleModifyComment: (commentId: string) => void;
11
13
  handleChangeContent: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
@@ -24,6 +24,6 @@ export declare const useComments: ({ defaultComments, options, type, callbacks,
24
24
  handleDeleteComment: (id: string) => void;
25
25
  handleCreateComment: (content: string) => void;
26
26
  handleModifyComment: (commentId: string) => void;
27
- handleUpdateComment: (comment: string) => void;
27
+ handleUpdateComment: (comment: string) => Promise<void>;
28
28
  handleReset: () => void;
29
29
  };
@@ -50,7 +50,7 @@ const useComments = ({
50
50
  handleModifyComment: (commentId) => {
51
51
  setEditCommentId(commentId);
52
52
  },
53
- handleUpdateComment: (comment) => {
53
+ handleUpdateComment: async (comment) => {
54
54
  editCommentId && (type === "edit" && (callbacks == null || callbacks.put({
55
55
  comment,
56
56
  commentId: editCommentId
@@ -5,6 +5,7 @@ export declare const useCommentsContext: () => {
5
5
  profiles: (import('../types').UserProfileResult | undefined)[];
6
6
  options: Partial<import('../types').CommentOptions>;
7
7
  type: import('../types').CommentType;
8
+ userRights?: Record<import('@edifice.io/client').RightRole, boolean>;
8
9
  setEditCommentId: (value: string | null) => void;
9
10
  handleModifyComment: (commentId: string) => void;
10
11
  handleChangeContent: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
@@ -46,7 +46,7 @@ const CommentProvider = ({
46
46
  defaultComments,
47
47
  callbacks: type == "edit" ? props.callbacks : null,
48
48
  options
49
- }), values = useMemo(
49
+ }), userRights = type === "edit" ? props.rights : void 0, values = useMemo(
50
50
  () => ({
51
51
  comments,
52
52
  content,
@@ -54,6 +54,7 @@ const CommentProvider = ({
54
54
  editCommentId,
55
55
  options,
56
56
  type,
57
+ userRights,
57
58
  setEditCommentId,
58
59
  handleCreateComment,
59
60
  handleModifyComment,
@@ -1,4 +1,4 @@
1
- import { UserProfile } from '@edifice.io/client';
1
+ import { RightRole, UserProfile } from '@edifice.io/client';
2
2
  export interface CommentProps {
3
3
  /**
4
4
  * Comment Id
@@ -61,6 +61,10 @@ interface EditRootProps extends BaseProps {
61
61
  * Callbacks to perform CRUD on comment
62
62
  */
63
63
  callbacks: CommentCallbacks;
64
+ /**
65
+ * Rights to perform CRUD on comment
66
+ */
67
+ rights?: Record<RightRole, boolean>;
64
68
  }
65
69
  interface ReadRootProps extends BaseProps {
66
70
  type: 'read';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edifice.io/react",
3
- "version": "2.0.0-develop-pedago.20250107165218",
3
+ "version": "2.0.0-develop-pedago.20250108121012",
4
4
  "description": "Edifice React Library",
5
5
  "keywords": [
6
6
  "react",
@@ -119,9 +119,9 @@
119
119
  "react-slugify": "^3.0.3",
120
120
  "swiper": "^10.1.0",
121
121
  "ua-parser-js": "^1.0.36",
122
- "@edifice.io/bootstrap": "2.0.0-develop-pedago.20250107165218",
123
- "@edifice.io/tiptap-extensions": "2.0.0-develop-pedago.20250107165218",
124
- "@edifice.io/utilities": "2.0.0-develop-pedago.20250107165218"
122
+ "@edifice.io/bootstrap": "2.0.0-develop-pedago.20250108121012",
123
+ "@edifice.io/tiptap-extensions": "2.0.0-develop-pedago.20250108121012",
124
+ "@edifice.io/utilities": "2.0.0-develop-pedago.20250108121012"
125
125
  },
126
126
  "devDependencies": {
127
127
  "@babel/plugin-transform-react-pure-annotations": "^7.23.3",
@@ -147,7 +147,7 @@
147
147
  "typescript-eslint": "^8.8.1",
148
148
  "vite": "^5.4.11",
149
149
  "vite-plugin-dts": "^4.1.0",
150
- "@edifice.io/client": "2.0.0-develop-pedago.20250107165218"
150
+ "@edifice.io/client": "2.0.0-develop-pedago.20250108121012"
151
151
  },
152
152
  "peerDependencies": {
153
153
  "@react-spring/web": "^9.7.5",