@edifice.io/react 2.6.9 → 2.6.10

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.
Files changed (31) hide show
  1. package/dist/components/RadioTile/RadioTile.d.ts +35 -0
  2. package/dist/components/RadioTile/RadioTile.js +22 -0
  3. package/dist/components/RadioTile/index.d.ts +2 -0
  4. package/dist/components/Tree/utilities/tree.js +21 -1
  5. package/dist/components/index.d.ts +1 -0
  6. package/dist/hooks/index.d.ts +2 -0
  7. package/dist/hooks/useBackground/useBackground.d.ts +1 -1
  8. package/dist/hooks/useCarbonioUnread/index.d.ts +1 -0
  9. package/dist/hooks/useCarbonioUnread/useCarbonioUnread.d.ts +5 -0
  10. package/dist/hooks/useCarbonioUnread/useCarbonioUnread.js +24 -0
  11. package/dist/hooks/useNextcloudSearch/index.d.ts +1 -0
  12. package/dist/hooks/useNextcloudSearch/useNextcloudSearch.d.ts +14 -0
  13. package/dist/hooks/useNextcloudSearch/useNextcloudSearch.js +64 -0
  14. package/dist/index.js +160 -150
  15. package/dist/modules/homepage/components/Header/Header.js +10 -3
  16. package/dist/modules/multimedia/FileCard/NextcloudFileCard.d.ts +25 -0
  17. package/dist/modules/multimedia/FileCard/NextcloudFileCard.js +102 -0
  18. package/dist/modules/multimedia/FileCard/index.d.ts +2 -0
  19. package/dist/modules/multimedia/MediaLibrary/MediaLibrary.d.ts +2 -2
  20. package/dist/modules/multimedia/MediaLibrary/MediaLibrary.js +36 -11
  21. package/dist/modules/multimedia/MediaLibrary/innertabs/Nextcloud.d.ts +1 -0
  22. package/dist/modules/multimedia/MediaLibrary/innertabs/Nextcloud.js +48 -0
  23. package/dist/modules/multimedia/MediaLibrary/innertabs/index.d.ts +1 -0
  24. package/dist/modules/multimedia/MediaLibrary/innertabs/index.js +2 -0
  25. package/dist/modules/multimedia/Nextcloud/Nextcloud.d.ts +24 -0
  26. package/dist/modules/multimedia/Nextcloud/Nextcloud.js +120 -0
  27. package/dist/modules/multimedia/Nextcloud/index.d.ts +2 -0
  28. package/dist/modules/multimedia/Workspace/Workspace.js +8 -5
  29. package/dist/modules/multimedia/index.d.ts +1 -0
  30. package/dist/multimedia.js +16 -12
  31. package/package.json +6 -6
@@ -16,7 +16,7 @@ import SvgIconNotificationBeta from "../../../icons/components/nav/IconNotificat
16
16
  import { useHasNotificationToday } from "../Notifications/hooks/useNotificationList.js";
17
17
  import useConversation from "../../../../hooks/useConversation/useConversation.js";
18
18
  import useUser from "../../../../hooks/useUser/useUser.js";
19
- import useHasWorkflow from "../../../../hooks/useHasWorkflow/useHasWorkflow.js";
19
+ import useCarbonioUnread from "../../../../hooks/useCarbonioUnread/useCarbonioUnread.js";
20
20
  import { useEdificeTheme } from "../../../../providers/EdificeThemeProvider/EdificeThemeProvider.hook.js";
21
21
  import useHover from "../../../../hooks/useHover/useHover.js";
22
22
  import LogoBeta from "../../../../components/LogoBeta/LogoBeta.js";
@@ -37,7 +37,10 @@ const Header = ({
37
37
  } = useConversation(), {
38
38
  user,
39
39
  avatar
40
- } = useUser(), hasCarbonioPreauthWorkflow = useHasWorkflow("org.entcore.auth.controllers.CarbonioPreauthController|preauth") || !1, classes = clsx("header-beta d-print-none no-2d no-1d"), {
40
+ } = useUser(), {
41
+ hasCarbonioWorkflow,
42
+ unreadCount: carbonioUnreadCount
43
+ } = useCarbonioUnread(), classes = clsx("header-beta d-print-none no-2d no-1d"), {
41
44
  userAvatar,
42
45
  userName,
43
46
  communitiesWorkflow,
@@ -62,8 +65,12 @@ const Header = ({
62
65
  level: "danger"
63
66
  }, className: "position-absolute", children: messages })
64
67
  ] }) }),
65
- hasCarbonioPreauthWorkflow && /* @__PURE__ */ jsx(NavItem, { children: /* @__PURE__ */ jsxs("a", { className: "nav-link position-relative", href: "/auth/carbonio/preauth", target: "_blank", "data-testid": "header-messagerie-button", children: [
68
+ hasCarbonioWorkflow && /* @__PURE__ */ jsx(NavItem, { children: /* @__PURE__ */ jsxs("a", { className: "nav-link position-relative", href: "/auth/carbonio/preauth", target: "_blank", "data-testid": "header-messagerie-button", children: [
66
69
  /* @__PURE__ */ jsx(SvgIconMessagesBeta, {}),
70
+ carbonioUnreadCount > 0 && /* @__PURE__ */ jsx(Badge, { variant: {
71
+ type: "notification",
72
+ level: "danger"
73
+ }, className: "position-absolute", children: carbonioUnreadCount }),
67
74
  /* @__PURE__ */ jsx(VisuallyHidden, { children: t("conversation") })
68
75
  ] }) }),
69
76
  /* @__PURE__ */ jsx(NavItem, { children: /* @__PURE__ */ jsx(NavLink, { link: "/welcome", translate: t("navbar.applications"), "data-testid": "header-my-apps-button", children: /* @__PURE__ */ jsx(SvgIconMyAppsBeta, {}) }) }),
@@ -0,0 +1,25 @@
1
+ import { ReactNode } from 'react';
2
+ import { NextcloudDocument } from '@edifice.io/client';
3
+ import { CardProps } from '../../../components/Card';
4
+ export interface NextcloudFileCardProps extends CardProps {
5
+ doc: NextcloudDocument;
6
+ /**
7
+ * Id of the user who owns the Nextcloud document, used to build the preview URL.
8
+ */
9
+ userId: string;
10
+ /**
11
+ * Custom icon to override the default based on file type
12
+ * Can be a string or a React node
13
+ */
14
+ customIcon?: ReactNode;
15
+ /**
16
+ * Custom color class to override the default based on file type
17
+ * Example: "bg-purple-300" or any valid CSS class
18
+ */
19
+ customColor?: string;
20
+ }
21
+ declare const NextcloudFileCard: {
22
+ ({ doc, userId, isClickable, isSelectable, isSelected, onClick, className, onSelect, isFocused, app, customIcon, customColor, }: NextcloudFileCardProps): import("react/jsx-runtime").JSX.Element;
23
+ displayName: string;
24
+ };
25
+ export default NextcloudFileCard;
@@ -0,0 +1,102 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useRef } from "react";
3
+ import { DocumentHelper, odeServices } from "@edifice.io/client";
4
+ import clsx from "clsx";
5
+ import SvgIconLandscape from "../../icons/components/IconLandscape.js";
6
+ import SvgIconMic from "../../icons/components/IconMic.js";
7
+ import SvgIconTextPage from "../../icons/components/IconTextPage.js";
8
+ import SvgIconVideo from "../../icons/components/IconVideo.js";
9
+ import FileIcon from "./FileIcon.js";
10
+ import useThumbnail from "../../../hooks/useThumbnail/useThumbnail.js";
11
+ import Card from "../../../components/Card/Card.js";
12
+ const roleMappings = {
13
+ csv: {
14
+ icon: ".CSV",
15
+ color: "bg-orange-200"
16
+ },
17
+ xls: {
18
+ icon: ".XLS",
19
+ color: "bg-green-200"
20
+ },
21
+ doc: {
22
+ icon: ".DOC",
23
+ color: "bg-blue-200"
24
+ },
25
+ txt: {
26
+ icon: ".TXT",
27
+ color: "bg-blue-200"
28
+ },
29
+ pdf: {
30
+ icon: ".PDF",
31
+ color: "bg-red-200"
32
+ },
33
+ audio: {
34
+ icon: /* @__PURE__ */ jsx(SvgIconMic, { width: 22, height: 22 }),
35
+ color: "bg-red-200"
36
+ },
37
+ ppt: {
38
+ icon: ".PPT",
39
+ color: "bg-red-200"
40
+ },
41
+ img: {
42
+ icon: /* @__PURE__ */ jsx(SvgIconLandscape, { width: 22, height: 22 }),
43
+ color: "bg-green-200"
44
+ },
45
+ video: {
46
+ icon: /* @__PURE__ */ jsx(SvgIconVideo, { width: 22, height: 22 }),
47
+ color: "bg-purple-200"
48
+ },
49
+ zip: {
50
+ icon: ".ZIP",
51
+ color: "bg-gray-300"
52
+ },
53
+ md: {
54
+ icon: ".MD",
55
+ color: "bg-blue-200"
56
+ },
57
+ unknown: {
58
+ icon: /* @__PURE__ */ jsx(SvgIconTextPage, { width: 22, height: 22 }),
59
+ color: "bg-gray-300"
60
+ }
61
+ };
62
+ function getRoleMap(type, customIcon, customColor) {
63
+ return customIcon !== void 0 || customColor !== void 0 ? {
64
+ icon: customIcon || /* @__PURE__ */ jsx(SvgIconTextPage, { width: 22, height: 22 }),
65
+ color: customColor || "bg-gray-300",
66
+ hasShadow: !1
67
+ } : roleMappings[type] ?? roleMappings.unknown;
68
+ }
69
+ const NextcloudFileCard = ({
70
+ doc,
71
+ userId,
72
+ isClickable = !0,
73
+ isSelectable = !1,
74
+ isSelected = !1,
75
+ onClick,
76
+ className,
77
+ onSelect,
78
+ isFocused,
79
+ app,
80
+ customIcon,
81
+ customColor
82
+ }) => {
83
+ const ref = useRef(null), type = DocumentHelper.role(doc.contentType, !1), roleMap = getRoleMap(type ?? "unknown", customIcon, customColor), file = clsx("file position-relative rounded", (roleMap == null ? void 0 : roleMap.color) ?? "bg-yellow-200"), mediaSrc = type === "img" ? odeServices.nextcloud().getFileUrl(userId, doc) : null, hasThumbnail = useThumbnail(mediaSrc, {
84
+ ref
85
+ }), imageStyles = hasThumbnail && {
86
+ backgroundImage: `url(${mediaSrc})`,
87
+ backgroundSize: "cover"
88
+ };
89
+ return /* @__PURE__ */ jsx(Card, { className: clsx("card-file", className), isClickable, isSelectable, isSelected, onClick, app, isFocused, onSelect, children: /* @__PURE__ */ jsxs(Card.Body, { space: "8", children: [
90
+ /* @__PURE__ */ jsx("div", { ref, className: file, style: {
91
+ aspectRatio: "16/10",
92
+ ...imageStyles
93
+ }, children: type !== "img" || !hasThumbnail ? /* @__PURE__ */ jsx(FileIcon, { type, roleMap }) : null }),
94
+ /* @__PURE__ */ jsxs("div", { className: "mt-4", children: [
95
+ /* @__PURE__ */ jsx(Card.Text, { children: doc.name }),
96
+ /* @__PURE__ */ jsx(Card.Text, { className: "text-black-50", children: doc == null ? void 0 : doc.ownerDisplayName })
97
+ ] })
98
+ ] }) });
99
+ };
100
+ export {
101
+ NextcloudFileCard as default
102
+ };
@@ -1,2 +1,4 @@
1
1
  export { default as FileCard } from './FileCard';
2
2
  export * from './FileCard';
3
+ export { default as NextcloudFileCard } from './NextcloudFileCard';
4
+ export * from './NextcloudFileCard';
@@ -1,4 +1,4 @@
1
- import { WorkspaceElement, WorkspaceVisibility } from '@edifice.io/client';
1
+ import { NextcloudDocument, WorkspaceElement, WorkspaceVisibility } from '@edifice.io/client';
2
2
  import { TabsItemProps } from '../../../components';
3
3
  import { ExternalLinkTabProps } from './innertabs/ExternalLink';
4
4
  import { InternalLinkTabProps, InternalLinkTabResult } from './innertabs/InternalLink';
@@ -54,7 +54,7 @@ export interface MediaLibraryRef {
54
54
  /**
55
55
  * The resulting type depends on the actual selected Tab when modal is closed.
56
56
  */
57
- export type MediaLibraryResult = WorkspaceElement[] | WorkspaceElement | InternalLinkTabResult | string | /*TODO type des autres résultats ?*/ any;
57
+ export type MediaLibraryResult = WorkspaceElement[] | WorkspaceElement | NextcloudDocument[] | InternalLinkTabResult | string | /*TODO type des autres résultats ?*/ any;
58
58
  /**
59
59
  * MediaLibrary component properties
60
60
  */
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
5
5
  import SvgIconApplications from "../../icons/components/IconApplications.js";
6
6
  import SvgIconCode from "../../icons/components/IconCode.js";
7
7
  import SvgIconFolder from "../../icons/components/IconFolder.js";
8
+ import SvgIconGlobe2 from "../../icons/components/IconGlobe2.js";
8
9
  import SvgIconGlobe from "../../icons/components/IconGlobe.js";
9
10
  import SvgIconMic from "../../icons/components/IconMic.js";
10
11
  import SvgIconRecordVideo from "../../icons/components/IconRecordVideo.js";
@@ -12,6 +13,7 @@ import SvgIconSmartphone from "../../icons/components/IconSmartphone.js";
12
13
  import { InnerTabs } from "./innertabs/index.js";
13
14
  import { MediaLibraryContext } from "./MediaLibraryContext.js";
14
15
  import useHasWorkflow from "../../../hooks/useHasWorkflow/useHasWorkflow.js";
16
+ import usePublicConf from "../../../hooks/usePublicConf/usePublicConf.js";
15
17
  import useHttpErrorToast from "../../../hooks/useHttpErrorToast/useHttpErrorToast.js";
16
18
  import Modal from "../../../components/Modal/Modal.js";
17
19
  import { Tabs } from "../../../components/Tabs/components/Tabs.js";
@@ -29,6 +31,8 @@ const orderedTabs = [
29
31
  // Filesystem browser + drag'n'drop of files
30
32
  "workspace",
31
33
  // Media browser
34
+ "nextcloud",
35
+ // Nextcloud media browser
32
36
  "video-embedder"
33
37
  // Link to a hosted video
34
38
  ], mediaLibraryTypes = {
@@ -70,7 +74,7 @@ const orderedTabs = [
70
74
  onCancel,
71
75
  onTabChange
72
76
  }, ref) => {
73
- var _a;
77
+ var _a, _b;
74
78
  const linkTabProps = useRef(), refModal = useRef(null);
75
79
  useImperativeHandle(ref, () => ({
76
80
  show,
@@ -81,7 +85,9 @@ const orderedTabs = [
81
85
  }));
82
86
  const {
83
87
  t
84
- } = useTranslation(), workspaceCreateWorkflow = useHasWorkflow("org.entcore.workspace.controllers.WorkspaceController|addDocument"), videoCaptureWorkflow = useHasWorkflow("com.opendigitaleducation.video.controllers.VideoController|capture"), [type, setType] = useState(null);
88
+ } = useTranslation(), workspaceCreateWorkflow = useHasWorkflow("org.entcore.workspace.controllers.WorkspaceController|addDocument"), videoCaptureWorkflow = useHasWorkflow("com.opendigitaleducation.video.controllers.VideoController|capture"), nextcloudViewWorkflow = useHasWorkflow("fr.openent.nextcloud.controller.NextcloudController|view"), {
89
+ data: workspacePublicConf
90
+ } = usePublicConf("workspace"), enableNextcloudTab = ((_a = workspacePublicConf == null ? void 0 : workspacePublicConf["folder-service"]) == null ? void 0 : _a.includes("nextcloud")) && nextcloudViewWorkflow, [type, setType] = useState(null);
85
91
  useHttpErrorToast({
86
92
  active: !!type,
87
93
  isDismissible: !0,
@@ -96,6 +102,14 @@ const orderedTabs = [
96
102
  availableFor: ["audio", "video", "image", "attachment"],
97
103
  isEnable: null
98
104
  },
105
+ nextcloud: {
106
+ id: "nextcloud",
107
+ icon: /* @__PURE__ */ jsx(SvgIconGlobe2, {}),
108
+ label: t("bbm.nextcloud"),
109
+ content: /* @__PURE__ */ jsx(InnerTabs.Nextcloud, {}),
110
+ availableFor: ["audio", "video", "image", "attachment"],
111
+ isEnable: () => !!enableNextcloudTab
112
+ },
99
113
  upload: {
100
114
  id: "upload",
101
115
  icon: /* @__PURE__ */ jsx(SvgIconSmartphone, {}),
@@ -162,7 +176,7 @@ const orderedTabs = [
162
176
  ), [defaultTabId, setDefaultTabId] = useState(), defaultTabIdx = useMemo(() => {
163
177
  const index = tabs.findIndex((t2) => t2.id === defaultTabId);
164
178
  return 0 > index || index >= tabs.length ? 0 : index;
165
- }, [tabs, defaultTabId]), [resultCounter, setResultCounter] = useState(), [result, setResult] = useState(), [deletionsOnCancel, setDeletionsOnCancel] = useState([]), [onSuccessAction, setPreSuccess] = useState();
179
+ }, [tabs, defaultTabId]), [resultCounter, setResultCounter] = useState(), [result, setResult] = useState(), [deletionsOnCancel, setDeletionsOnCancel] = useState([]), [onSuccessAction, setPreSuccess] = useState(), [isSubmitting, setIsSubmitting] = useState(!1);
166
180
  function setVisibleTab(tab) {
167
181
  throw tabs.findIndex((t2) => t2.id === tab) < 0 ? "tab.not.visible" : "not.implemented.yet";
168
182
  }
@@ -177,22 +191,33 @@ const orderedTabs = [
177
191
  linkTabProps.current = props, "resourceId" in props || "appPrefix" in props || setDefaultTabId("external-link"), setType("hyperlink");
178
192
  };
179
193
  useEffect(() => {
180
- var _a2, _b;
194
+ var _a2, _b2;
181
195
  const typeKey = type || "none";
182
- !defaultTabId && typeof ((_a2 = mediaLibraryTypes[typeKey]) == null ? void 0 : _a2.defaultTab) == "string" && setDefaultTabId((_b = mediaLibraryTypes[typeKey]) == null ? void 0 : _b.defaultTab);
196
+ !defaultTabId && typeof ((_a2 = mediaLibraryTypes[typeKey]) == null ? void 0 : _a2.defaultTab) == "string" && setDefaultTabId((_b2 = mediaLibraryTypes[typeKey]) == null ? void 0 : _b2.defaultTab);
183
197
  }, [defaultTabId, type]);
184
- const modalHeader = t(((_a = mediaLibraryTypes[type ?? "none"]) == null ? void 0 : _a.title) ?? "bbm"), resetState = () => {
198
+ const modalHeader = t(((_b = mediaLibraryTypes[type ?? "none"]) == null ? void 0 : _b.title) ?? "bbm"), resetState = () => {
185
199
  linkTabProps.current = void 0, setResult(void 0), setResultCounter(void 0), setDefaultTabId(void 0), setPreSuccess(void 0), setDeletionsOnCancel([]);
186
200
  }, handleTabChange = (tab) => {
187
201
  onTabChange == null || onTabChange(tab, deletionsOnCancel), resetState();
188
202
  }, handleOnSuccess = useCallback(() => {
203
+ if (isSubmitting) return;
189
204
  const triggerSuccess = async (result2) => {
190
205
  result2 instanceof Array && ["protected", "public"].findIndex((v) => v === visibility) >= 0 && (result2 = await odeServices.workspace().transferDocuments(result2, appCode ?? "media-library", visibility)), onSuccess(result2);
191
206
  };
192
- onSuccessAction ? onSuccessAction().then((result2) => {
193
- triggerSuccess(result2);
194
- }) : result && triggerSuccess(result), resetState();
195
- }, [onSuccessAction, result, onSuccess, visibility, appCode]), handleOnCancel = () => {
207
+ (async () => {
208
+ setIsSubmitting(!0);
209
+ try {
210
+ if (onSuccessAction) {
211
+ const asyncResult = await onSuccessAction();
212
+ await triggerSuccess(asyncResult);
213
+ } else result && await triggerSuccess(result);
214
+ resetState();
215
+ } catch {
216
+ } finally {
217
+ setIsSubmitting(!1);
218
+ }
219
+ })();
220
+ }, [isSubmitting, onSuccessAction, result, onSuccess, visibility, appCode]), handleOnCancel = () => {
196
221
  onCancel(deletionsOnCancel), resetState();
197
222
  };
198
223
  return type && /* @__PURE__ */ jsx(MediaLibraryContext.Provider, { value: {
@@ -214,7 +239,7 @@ const orderedTabs = [
214
239
  ] }) }),
215
240
  /* @__PURE__ */ jsxs(Modal.Footer, { children: [
216
241
  /* @__PURE__ */ jsx(Button, { type: "button", color: "tertiary", variant: "ghost", onClick: handleOnCancel, children: t("cancel") }),
217
- /* @__PURE__ */ jsx(Button, { type: "button", color: "primary", variant: "filled", disabled: typeof result > "u", onClick: handleOnSuccess, children: resultCounter && resultCounter > 1 ? t("addMultiple", {
242
+ /* @__PURE__ */ jsx(Button, { type: "button", color: "primary", variant: "filled", disabled: typeof result > "u" || isSubmitting, onClick: handleOnSuccess, children: resultCounter && resultCounter > 1 ? t("addMultiple", {
218
243
  number: resultCounter
219
244
  }) : t("add") })
220
245
  ] })
@@ -0,0 +1 @@
1
+ export declare const Nextcloud: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { odeServices } from "@edifice.io/client";
3
+ import { useMediaLibraryContext } from "../MediaLibraryContext.js";
4
+ import useUser from "../../../../hooks/useUser/useUser.js";
5
+ import Nextcloud$1 from "../../Nextcloud/Nextcloud.js";
6
+ const Nextcloud = () => {
7
+ const {
8
+ appCode,
9
+ visibility,
10
+ type,
11
+ setResultCounter,
12
+ setResult,
13
+ setPreSuccess,
14
+ multiple
15
+ } = useMediaLibraryContext(), {
16
+ user
17
+ } = useUser();
18
+ function getDocumentRoleFilter() {
19
+ switch (type) {
20
+ case "image":
21
+ return "img";
22
+ case "audio":
23
+ return "audio";
24
+ case "video":
25
+ return "video";
26
+ default:
27
+ return null;
28
+ }
29
+ }
30
+ function handleSelect(result) {
31
+ setResultCounter(result.length), result.length ? (setResult(result), setPreSuccess(() => () => user != null && user.userId ? odeServices.nextcloud().copyDocumentToWorkspace(
32
+ user.userId,
33
+ result.map((doc) => doc.path),
34
+ void 0,
35
+ // Copy the documents straight to their final place, the way an
36
+ // upload does, instead of leaving a copy in the user's own
37
+ // documents for the modal to transfer afterwards.
38
+ {
39
+ application: appCode,
40
+ visibility
41
+ }
42
+ ) : Promise.resolve([]))) : (setResult(), setPreSuccess(void 0));
43
+ }
44
+ return /* @__PURE__ */ jsx(Nextcloud$1, { roles: getDocumentRoleFilter(), onSelect: handleSelect, multiple, className: "border rounded overflow-y-auto" });
45
+ };
46
+ export {
47
+ Nextcloud
48
+ };
@@ -4,6 +4,7 @@ export declare const InnerTabs: {
4
4
  Upload: () => import("react/jsx-runtime").JSX.Element;
5
5
  ExternalLink: ({ link, multiNodeSelected, }: import('./ExternalLink').ExternalLinkTabProps) => import("react/jsx-runtime").JSX.Element;
6
6
  Workspace: () => import("react/jsx-runtime").JSX.Element;
7
+ Nextcloud: () => import("react/jsx-runtime").JSX.Element;
7
8
  InternalLink: ({ target, resourceId, appPrefix, }: import('./InternalLink').InternalLinkTabProps) => import("react/jsx-runtime").JSX.Element;
8
9
  Iframe: () => import("react/jsx-runtime").JSX.Element;
9
10
  VideoEmbedder: () => import("react/jsx-runtime").JSX.Element;
@@ -2,6 +2,7 @@ import { Audio } from "./Audio.js";
2
2
  import { ExternalLink } from "./ExternalLink.js";
3
3
  import { Iframe } from "./Iframe.js";
4
4
  import { InternalLink } from "./InternalLink.js";
5
+ import { Nextcloud } from "./Nextcloud.js";
5
6
  import { Upload } from "./Upload.js";
6
7
  import { Video } from "./Video.js";
7
8
  import { VideoEmbedder } from "./VideoEmbedder.js";
@@ -12,6 +13,7 @@ const InnerTabs = {
12
13
  Upload,
13
14
  ExternalLink,
14
15
  Workspace,
16
+ Nextcloud,
15
17
  InternalLink,
16
18
  Iframe,
17
19
  VideoEmbedder
@@ -0,0 +1,24 @@
1
+ import { NextcloudDocument, Role } from '@edifice.io/client';
2
+ /**
3
+ * Nextcloud component properties
4
+ */
5
+ export interface NextcloudProps {
6
+ /**
7
+ * Notify parent when media elements are successfully selected.
8
+ */
9
+ onSelect: (result: NextcloudDocument[]) => void;
10
+ /**
11
+ * Boolean to know if we can select 1 or many files.
12
+ */
13
+ multiple?: boolean | undefined;
14
+ /**
15
+ * Document roles to filter files by; null (default) shows all roles.
16
+ */
17
+ roles?: Role | Role[] | null;
18
+ /**
19
+ * Optional class for styling purpose
20
+ */
21
+ className?: string;
22
+ }
23
+ declare const Nextcloud: ({ onSelect, multiple, roles, className, }: NextcloudProps) => import("react/jsx-runtime").JSX.Element;
24
+ export default Nextcloud;
@@ -0,0 +1,120 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, useCallback, useEffect, useMemo } from "react";
3
+ import { DocumentHelper } from "@edifice.io/client";
4
+ import clsx from "clsx";
5
+ import { useTranslation } from "react-i18next";
6
+ import { findNodeById } from "../../../components/Tree/utilities/tree.js";
7
+ import SvgIconSortAscendingLetters from "../../icons/components/IconSortAscendingLetters.js";
8
+ import SvgIconSortDescendingLetters from "../../icons/components/IconSortDescendingLetters.js";
9
+ import SvgIconSortTime from "../../icons/components/IconSortTime.js";
10
+ import illuError from "@edifice.io/bootstrap/dist/images/emptyscreen/illu-error.svg";
11
+ import illuConnectionLost from "@edifice.io/bootstrap/dist/images/emptyscreen/illu-connection-lost.svg";
12
+ import illuTrash from "@edifice.io/bootstrap/dist/images/emptyscreen/illu-trash.svg";
13
+ import useUser from "../../../hooks/useUser/useUser.js";
14
+ import useToast from "../../../hooks/useToast/useToast.js";
15
+ import useNextcloudSearch from "../../../hooks/useNextcloudSearch/useNextcloudSearch.js";
16
+ import LoadingScreen from "../../../components/LoadingScreen/LoadingScreen.js";
17
+ import Flex from "../../../components/Flex/Flex.js";
18
+ import EmptyScreen from "../../../components/EmptyScreen/EmptyScreen.js";
19
+ import Button from "../../../components/Button/Button.js";
20
+ import { Grid } from "../../../components/Grid/Grid.js";
21
+ import Tree from "../../../components/Tree/components/Tree.js";
22
+ import SearchBar from "../../../components/SearchBar/SearchBar.js";
23
+ import Dropdown from "../../../components/Dropdown/Dropdown.js";
24
+ import NextcloudFileCard from "../FileCard/NextcloudFileCard.js";
25
+ const ROOT_ID = "root";
26
+ function compare(a, b) {
27
+ return a === b ? 0 : a === void 0 ? -1 : b === void 0 ? 1 : a.localeCompare(b);
28
+ }
29
+ const Nextcloud = ({
30
+ onSelect,
31
+ multiple = !0,
32
+ roles,
33
+ className
34
+ }) => {
35
+ const {
36
+ t
37
+ } = useTranslation(), {
38
+ user
39
+ } = useUser(), toast = useToast(), {
40
+ root,
41
+ needsAuth,
42
+ isCheckingAuth,
43
+ isAuthError,
44
+ refetchAuthStatus,
45
+ loadContent,
46
+ loadError
47
+ } = useNextcloudSearch(ROOT_ID, t("nextcloud"), user == null ? void 0 : user.userId), popupRef = useRef(null), [currentNodeId, setCurrentNodeId] = useState(ROOT_ID), currentNode = findNodeById(root, currentNodeId) ?? root, [searchTerm, setSearchTerm] = useState(void 0), [sortOrder, setSortOrder] = useState(["modified", "desc"]), [selectedDocuments, setSelectedDocuments] = useState([]), handleTreeItemChange = useCallback((nodeId) => {
48
+ setCurrentNodeId(nodeId), loadContent(nodeId);
49
+ }, [loadContent]);
50
+ useEffect(() => {
51
+ needsAuth || loadContent(ROOT_ID);
52
+ }, [loadContent, needsAuth]);
53
+ const documents = useMemo(() => {
54
+ if (!currentNode.files) return;
55
+ const matchesRole = (doc) => {
56
+ if (!roles) return !0;
57
+ const role = DocumentHelper.role(doc.contentType, !1);
58
+ return Array.isArray(roles) ? roles.includes(role) : roles === role;
59
+ }, normalizedSearchTerm = searchTerm == null ? void 0 : searchTerm.toLowerCase(), list = currentNode.files.filter((f) => (!normalizedSearchTerm || f.name.toLowerCase().includes(normalizedSearchTerm)) && matchesRole(f));
60
+ let sortFunction;
61
+ return sortOrder[0] === "name" ? sortFunction = sortOrder[1] === "asc" ? (a, b) => compare(a.name, b.name) : (a, b) => compare(b.name, a.name) : sortFunction = (a, b) => compare(b.lastModified, a.lastModified), list.sort(sortFunction);
62
+ }, [currentNode, searchTerm, sortOrder, roles]), selectedPaths = useMemo(() => new Set(selectedDocuments.map((d) => d.path)), [selectedDocuments]), handleSearchChange = useCallback((e) => {
63
+ setSearchTerm(e.target.value);
64
+ }, [setSearchTerm]);
65
+ function getSortOrderLabel() {
66
+ return sortOrder[0] === "name" ? sortOrder[1] === "asc" ? t("sort.order.alpha.asc") : t("sort.order.alpha.desc") : t("sort.order.modify.desc");
67
+ }
68
+ function handleSelectDoc(doc) {
69
+ let currentDocuments = [...selectedDocuments];
70
+ multiple ? currentDocuments.some((selectedDocument) => selectedDocument.path === doc.path) ? currentDocuments = currentDocuments.filter((selectedDocument) => selectedDocument.path !== doc.path) : currentDocuments = [...currentDocuments, doc] : currentDocuments = [doc], setSelectedDocuments(currentDocuments), onSelect(currentDocuments);
71
+ }
72
+ const nextcloud = clsx("workspace flex-grow-1 gap-0", className), openLoginPopup = () => {
73
+ popupRef.current = window.open(`${window.location.origin}/nextcloud/user/oauth2/init`, "", "popup, height=600, width=400"), popupRef.current || toast.error(t("nextcloud.auth.popupBlocked"));
74
+ };
75
+ return useEffect(() => {
76
+ function handleMessage(event) {
77
+ var _a;
78
+ event.origin !== window.location.origin || ((_a = event.data) == null ? void 0 : _a.type) !== "nextcloud-connected" || (popupRef.current && !popupRef.current.closed && popupRef.current.close(), refetchAuthStatus());
79
+ }
80
+ return window.addEventListener("message", handleMessage), () => window.removeEventListener("message", handleMessage);
81
+ }, [refetchAuthStatus]), isCheckingAuth ? /* @__PURE__ */ jsx(LoadingScreen, {}) : isAuthError ? /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "12", className: "h-full w-100", justify: "center", align: "center", children: [
82
+ /* @__PURE__ */ jsx(EmptyScreen, { imageSrc: illuError, title: t("nextcloud.error.title"), text: t("nextcloud.error.description") }),
83
+ /* @__PURE__ */ jsx(Button, { onClick: () => refetchAuthStatus(), children: t("retry") })
84
+ ] }) : needsAuth ? /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "12", className: "h-full w-100", justify: "center", align: "center", children: [
85
+ /* @__PURE__ */ jsx(EmptyScreen, { imageSrc: illuConnectionLost, title: t("nextcloud.auth.title"), text: t("nextcloud.auth.description") }),
86
+ /* @__PURE__ */ jsx(Button, { onClick: openLoginPopup, children: t("nextcloud.auth.connect") })
87
+ ] }) : /* @__PURE__ */ jsxs(Grid, { className: nextcloud, children: [
88
+ /* @__PURE__ */ jsx(Grid.Col, { sm: "12", md: "3", xl: "4", className: "workspace-folders p-12 pt-0 gap-12", children: /* @__PURE__ */ jsx("div", { style: {
89
+ position: "sticky",
90
+ top: 0,
91
+ paddingTop: "1.2rem"
92
+ }, children: /* @__PURE__ */ jsx(Tree, { nodes: root, selectedNodeId: currentNodeId, showIcon: !0, onTreeItemClick: handleTreeItemChange, onTreeItemUnfold: handleTreeItemChange }) }) }),
93
+ /* @__PURE__ */ jsx(Grid.Col, { sm: "12", md: "5", xl: "8", children: /* @__PURE__ */ jsxs(Grid, { className: "flex-grow-1 gap-0", children: [
94
+ /* @__PURE__ */ jsxs(Grid.Col, { sm: "4", md: "8", xl: "12", children: [
95
+ /* @__PURE__ */ jsx("div", { className: "workspace-search px-16 py-8 ", children: /* @__PURE__ */ jsx(SearchBar, { isVariant: !0, className: "gap-16", onChange: handleSearchChange }) }),
96
+ /* @__PURE__ */ jsxs(Flex, { className: "px-8 py-4", align: "center", justify: "end", children: [
97
+ /* @__PURE__ */ jsx("small", { className: "text-muted", children: t("workspace.search.order") }),
98
+ /* @__PURE__ */ jsxs(Dropdown, { children: [
99
+ /* @__PURE__ */ jsx(Dropdown.Trigger, { size: "sm", label: getSortOrderLabel(), variant: "ghost" }),
100
+ /* @__PURE__ */ jsxs(Dropdown.Menu, { children: [
101
+ /* @__PURE__ */ jsx(Dropdown.Item, { icon: /* @__PURE__ */ jsx(SvgIconSortTime, {}), onClick: () => setSortOrder(["modified", "desc"]), children: t("sort.order.modify.desc") }),
102
+ /* @__PURE__ */ jsx(Dropdown.Item, { icon: /* @__PURE__ */ jsx(SvgIconSortAscendingLetters, {}), onClick: () => setSortOrder(["name", "asc"]), children: t("sort.order.alpha.asc") }),
103
+ /* @__PURE__ */ jsx(Dropdown.Item, { icon: /* @__PURE__ */ jsx(SvgIconSortDescendingLetters, {}), onClick: () => setSortOrder(["name", "desc"]), children: t("sort.order.alpha.desc") })
104
+ ] })
105
+ ] })
106
+ ] })
107
+ ] }),
108
+ /* @__PURE__ */ jsx(Grid.Col, { sm: "4", md: "8", xl: "12", className: "p-8 gap-8", children: loadError ? /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "12", className: "h-full w-100", justify: "center", align: "center", children: [
109
+ /* @__PURE__ */ jsx(EmptyScreen, { imageSrc: illuError, title: t("nextcloud.error.title"), text: t("nextcloud.error.description") }),
110
+ /* @__PURE__ */ jsx(Button, { onClick: () => loadContent(currentNodeId), children: t("retry") })
111
+ ] }) : documents ? documents.length !== 0 ? /* @__PURE__ */ jsx("div", { className: "grid grid-workspace", children: documents.map((doc) => {
112
+ const isSelected = selectedPaths.has(doc.path);
113
+ return /* @__PURE__ */ jsx(NextcloudFileCard, { doc, userId: user.userId, isSelected, onClick: () => handleSelectDoc(doc) }, doc.path);
114
+ }) }) : /* @__PURE__ */ jsx(EmptyScreen, { imageSrc: illuTrash, text: t("workspace.empty.docSpace"), title: t("explorer.emptyScreen.trash.title") }) : /* @__PURE__ */ jsx(LoadingScreen, {}) })
115
+ ] }) })
116
+ ] });
117
+ };
118
+ export {
119
+ Nextcloud as default
120
+ };
@@ -0,0 +1,2 @@
1
+ export { default as Nextcloud } from './Nextcloud';
2
+ export * from './Nextcloud';
@@ -6,6 +6,7 @@ import SvgIconSortAscendingLetters from "../../icons/components/IconSortAscendin
6
6
  import SvgIconSortDescendingLetters from "../../icons/components/IconSortDescendingLetters.js";
7
7
  import SvgIconSortTime from "../../icons/components/IconSortTime.js";
8
8
  import illuTrash from "@edifice.io/bootstrap/dist/images/emptyscreen/illu-trash.svg";
9
+ import useHasWorkflow from "../../../hooks/useHasWorkflow/useHasWorkflow.js";
9
10
  import useWorkspaceSearch from "../../../hooks/useWorkspaceSearch/useWorkspaceSearch.js";
10
11
  import { Grid } from "../../../components/Grid/Grid.js";
11
12
  import TreeView from "../../../components/TreeView/TreeView.js";
@@ -15,7 +16,7 @@ import LoadingScreen from "../../../components/LoadingScreen/LoadingScreen.js";
15
16
  import FileCard from "../FileCard/FileCard.js";
16
17
  import EmptyScreen from "../../../components/EmptyScreen/EmptyScreen.js";
17
18
  import { findTreeNode } from "../../../components/TreeView/utilities/treeview.js";
18
- const Workspace = ({
19
+ const WORKSPACE_VIEW_WORKFLOW = "org.entcore.workspace.controllers.WorkspaceController|view", Workspace = ({
19
20
  roles,
20
21
  onSelect,
21
22
  multiple = !0,
@@ -25,7 +26,7 @@ const Workspace = ({
25
26
  }) => {
26
27
  const {
27
28
  t
28
- } = useTranslation(), {
29
+ } = useTranslation(), hasWorkspaceViewRight = useHasWorkflow(WORKSPACE_VIEW_WORKFLOW), canViewPersonalFolders = !!hasWorkspaceViewRight, {
29
30
  root: ownerRoot,
30
31
  loadContent: loadOwnerDocs
31
32
  } = useWorkspaceSearch("root", t("workspace.tree.owner"), "owner", roles), {
@@ -111,7 +112,9 @@ const Workspace = ({
111
112
  return;
112
113
  }
113
114
  (_a = ref == null ? void 0 : ref.current) == null || _a.select("root");
114
- }, [currentFilter]), useEffect(loadContent, [loadContent]), useEffect(() => {
115
+ }, [currentFilter]), useEffect(() => {
116
+ hasWorkspaceViewRight === !1 && (currentFilter === "owner" || currentFilter === "shared") && selectAndLoadContent("protected", "root");
117
+ }, [hasWorkspaceViewRight]), useEffect(loadContent, [loadContent]), useEffect(() => {
115
118
  if (currentNode.files) {
116
119
  let list = [].concat(currentNode.files);
117
120
  searchTerm && (list = list.filter((f) => f.name.indexOf(searchTerm) >= 0));
@@ -140,8 +143,8 @@ const Workspace = ({
140
143
  top: 0,
141
144
  paddingTop: "1.2rem"
142
145
  }, children: [
143
- /* @__PURE__ */ jsx(TreeView, { ref: ownerRef, data: ownerRoot, onTreeItemClick: (nodeId) => selectAndLoadContent("owner", nodeId), onTreeItemUnfold: (nodeId) => selectAndLoadContent("owner", nodeId) }),
144
- /* @__PURE__ */ jsx(TreeView, { ref: sharedRef, data: sharedRoot, onTreeItemClick: (nodeId) => selectAndLoadContent("shared", nodeId), onTreeItemUnfold: (nodeId) => selectAndLoadContent("shared", nodeId) }),
146
+ canViewPersonalFolders && /* @__PURE__ */ jsx(TreeView, { ref: ownerRef, data: ownerRoot, onTreeItemClick: (nodeId) => selectAndLoadContent("owner", nodeId), onTreeItemUnfold: (nodeId) => selectAndLoadContent("owner", nodeId) }),
147
+ canViewPersonalFolders && /* @__PURE__ */ jsx(TreeView, { ref: sharedRef, data: sharedRoot, onTreeItemClick: (nodeId) => selectAndLoadContent("shared", nodeId), onTreeItemUnfold: (nodeId) => selectAndLoadContent("shared", nodeId) }),
145
148
  /* @__PURE__ */ jsx(TreeView, { ref: protectRef, data: protectRoot, onTreeItemClick: (nodeId) => selectAndLoadContent("protected", nodeId), onTreeItemUnfold: (nodeId) => selectAndLoadContent("protected", nodeId) }),
146
149
  showPublicFolder && /* @__PURE__ */ jsx(TreeView, { ref: publicRef, data: publicRoot, onTreeItemClick: (nodeId) => selectAndLoadContent("public", nodeId), onTreeItemUnfold: (nodeId) => selectAndLoadContent("public", nodeId) })
147
150
  ] }) }),
@@ -5,6 +5,7 @@ export * from './ImagePicker';
5
5
  export * from './FileCard';
6
6
  export * from './Linker';
7
7
  export * from './MediaLibrary';
8
+ export * from './Nextcloud';
8
9
  export * from './UploadCard';
9
10
  export * from './VideoEmbed';
10
11
  export * from './VideoRecorder';
@@ -4,12 +4,14 @@ import { default as default4 } from "./modules/multimedia/FileCard/FileCard.js";
4
4
  import { default as default5 } from "./modules/multimedia/ImageEditor/components/ImageEditor.js";
5
5
  import { default as default6 } from "./modules/multimedia/ImagePicker/ImagePicker.js";
6
6
  import { default as default7 } from "./modules/multimedia/MediaLibrary/MediaLibrary.js";
7
- import { default as default8 } from "./modules/multimedia/UploadCard/UploadCard.js";
8
- import { default as default9 } from "./modules/multimedia/UploadFiles/UploadFiles.js";
9
- import { default as default10 } from "./modules/multimedia/VideoEmbed/VideoEmbed.js";
10
- import { default as default11 } from "./modules/multimedia/VideoRecorder/VideoRecorder.js";
11
- import { default as default12 } from "./modules/multimedia/Workspace/Workspace.js";
12
- import { default as default13 } from "./modules/multimedia/WorkspaceFolders/WorkspaceFolders.js";
7
+ import { default as default8 } from "./modules/multimedia/Nextcloud/Nextcloud.js";
8
+ import { default as default9 } from "./modules/multimedia/FileCard/NextcloudFileCard.js";
9
+ import { default as default10 } from "./modules/multimedia/UploadCard/UploadCard.js";
10
+ import { default as default11 } from "./modules/multimedia/UploadFiles/UploadFiles.js";
11
+ import { default as default12 } from "./modules/multimedia/VideoEmbed/VideoEmbed.js";
12
+ import { default as default13 } from "./modules/multimedia/VideoRecorder/VideoRecorder.js";
13
+ import { default as default14 } from "./modules/multimedia/Workspace/Workspace.js";
14
+ import { default as default15 } from "./modules/multimedia/WorkspaceFolders/WorkspaceFolders.js";
13
15
  import { ExternalLinker } from "./modules/multimedia/Linker/ExternalLinker/ExternalLinker.js";
14
16
  import { InternalLinker } from "./modules/multimedia/Linker/InternalLinker/InternalLinker.js";
15
17
  import { Upload } from "./modules/multimedia/MediaLibrary/innertabs/Upload.js";
@@ -22,11 +24,13 @@ export {
22
24
  default6 as ImagePicker,
23
25
  InternalLinker,
24
26
  default7 as MediaLibrary,
27
+ default8 as Nextcloud,
28
+ default9 as NextcloudFileCard,
25
29
  Upload,
26
- default8 as UploadCard,
27
- default9 as UploadFiles,
28
- default10 as VideoEmbed,
29
- default11 as VideoRecorder,
30
- default12 as Workspace,
31
- default13 as WorkspaceFolders
30
+ default10 as UploadCard,
31
+ default11 as UploadFiles,
32
+ default12 as VideoEmbed,
33
+ default13 as VideoRecorder,
34
+ default14 as Workspace,
35
+ default15 as WorkspaceFolders
32
36
  };