@edifice.io/react 2.6.5-develop-b2school.20260907142010 → 2.6.5-develop-pedago.20260909143307
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/dist/hooks/useUploadFiles/index.d.ts +1 -0
- package/dist/hooks/useUploadFiles/useUploadFiles.d.ts +11 -1
- package/dist/hooks/useUploadFiles/useUploadFiles.js +12 -7
- package/dist/modules/homepage/components/Header/Header.js +4 -11
- package/dist/modules/homepage/components/UserSpace/hooks/useProfileLinks.js +8 -18
- package/dist/modules/multimedia/MediaLibrary/innertabs/Upload.js +34 -7
- package/dist/modules/multimedia/UploadFiles/UploadFiles.d.ts +2 -1
- package/package.json +6 -6
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { WorkspaceElement, WorkspaceVisibility } from '@edifice.io/client';
|
|
2
|
+
/**
|
|
3
|
+
* Snapshot of a source file taken at upload time, so the upload result can be
|
|
4
|
+
* re-ordered later on against the original file metadata.
|
|
5
|
+
*/
|
|
6
|
+
export interface UploadSourceFileInfo {
|
|
7
|
+
/** Original file name. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** `File.lastModified` of the source file (ms since epoch). */
|
|
10
|
+
lastModified: number;
|
|
11
|
+
}
|
|
2
12
|
declare const useUploadFiles: ({ handleOnChange, visibility, application, }: {
|
|
3
|
-
handleOnChange: (uploadedFiles: WorkspaceElement[]) => void;
|
|
13
|
+
handleOnChange: (uploadedFiles: WorkspaceElement[], sourceFilesInfo: Record<string, UploadSourceFileInfo>) => void;
|
|
4
14
|
visibility?: WorkspaceVisibility;
|
|
5
15
|
application?: string;
|
|
6
16
|
}) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect } from "react";
|
|
1
|
+
import { useState, useRef, useCallback, useEffect } from "react";
|
|
2
2
|
import { ImageResizer, addTimestampToImageUrl } from "@edifice.io/utilities";
|
|
3
3
|
import { useDropzoneContext } from "../../components/Dropzone/DropzoneContext.js";
|
|
4
4
|
import useWorkspaceFile from "../useWorkspaceFile/useWorkspaceFile.js";
|
|
@@ -8,7 +8,7 @@ const useUploadFiles = ({
|
|
|
8
8
|
visibility,
|
|
9
9
|
application
|
|
10
10
|
}) => {
|
|
11
|
-
const [uploadedFiles, setUploadedFiles] = useState([]), [editingImage, setEditingImage] = useState(void 0), {
|
|
11
|
+
const [uploadedFiles, setUploadedFiles] = useState([]), sourceFilesInfoRef = useRef({}), [editingImage, setEditingImage] = useState(void 0), {
|
|
12
12
|
files,
|
|
13
13
|
deleteFile,
|
|
14
14
|
replaceFileAt,
|
|
@@ -34,7 +34,10 @@ const useUploadFiles = ({
|
|
|
34
34
|
} catch (err) {
|
|
35
35
|
console.error(err);
|
|
36
36
|
}
|
|
37
|
-
!resource && !replacement && (resource = await uploadFile(file)), resource ?
|
|
37
|
+
!resource && !replacement && (resource = await uploadFile(file)), resource ? (resource._id && (sourceFilesInfoRef.current[resource._id] = {
|
|
38
|
+
name: file.name,
|
|
39
|
+
lastModified: file.lastModified
|
|
40
|
+
}), setUploadedFiles((prevFiles) => [...prevFiles, resource])) : resetInputValue();
|
|
38
41
|
});
|
|
39
42
|
}, [uploadAlternateFile, uploadFile, replaceFileAt]);
|
|
40
43
|
useEffect(() => {
|
|
@@ -47,15 +50,17 @@ const useUploadFiles = ({
|
|
|
47
50
|
newFiles.forEach((file) => file && setUploadStatus(file, "idle")), tryUploading(newFiles);
|
|
48
51
|
}, [files, uploadedFiles, getUploadStatus, setUploadStatus, tryUploading]), useEffect(() => {
|
|
49
52
|
const sortedUploadedFiles = sortUploadedFiles(files, uploadedFiles);
|
|
50
|
-
handleOnChange(sortedUploadedFiles
|
|
53
|
+
handleOnChange(sortedUploadedFiles, {
|
|
54
|
+
...sourceFilesInfoRef.current
|
|
55
|
+
});
|
|
51
56
|
}, [uploadedFiles]);
|
|
52
57
|
const sortUploadedFiles = (filesArray, uploadedFilesArray) => {
|
|
53
|
-
const orderMap = filesArray.reduce((acc, item, index) => (acc[item.name] = index, acc), {});
|
|
54
|
-
return uploadedFilesArray.sort((a, b) => orderMap[a.name] - orderMap[b.name]);
|
|
58
|
+
const orderMap = filesArray.reduce((acc, item, index) => (item.name in acc || (acc[item.name] = index), acc), {});
|
|
59
|
+
return [...uploadedFilesArray].sort((a, b) => (orderMap[a.name] ?? Number.MAX_SAFE_INTEGER) - (orderMap[b.name] ?? Number.MAX_SAFE_INTEGER));
|
|
55
60
|
};
|
|
56
61
|
async function removeFile(file) {
|
|
57
62
|
const resource = uploadedFiles.find((uploadedFile) => uploadedFile.name === file.name);
|
|
58
|
-
resource && (await remove(resource), clearUploadStatus(file), setUploadedFiles((prevFiles) => prevFiles.filter((prevFile) => prevFile.name !== (resource == null ? void 0 : resource.name)))), deleteFile(file), resetInputValue();
|
|
63
|
+
resource && (await remove(resource), clearUploadStatus(file), resource._id && delete sourceFilesInfoRef.current[resource._id], setUploadedFiles((prevFiles) => prevFiles.filter((prevFile) => prevFile.name !== (resource == null ? void 0 : resource.name)))), deleteFile(file), resetInputValue();
|
|
59
64
|
}
|
|
60
65
|
async function updateImage({
|
|
61
66
|
blob,
|
|
@@ -6,7 +6,6 @@ import { Navbar } from "../../../../components/Layout/components/Navbar.js";
|
|
|
6
6
|
import { NavItem } from "../../../../components/Layout/components/NavItem.js";
|
|
7
7
|
import { NavLink } from "../../../../components/Layout/components/NavLink.js";
|
|
8
8
|
import useHeader from "../../../../components/Layout/hooks/useHeader.js";
|
|
9
|
-
import SvgIconSetBackground from "../../../icons/components/IconSetBackground.js";
|
|
10
9
|
import SvgIconCommunitiesBeta from "../../../icons/components/nav/IconCommunitiesBeta.js";
|
|
11
10
|
import SvgIconDisconnect from "../../../icons/components/nav/IconDisconnect.js";
|
|
12
11
|
import SvgIconHomeBeta from "../../../icons/components/nav/IconHomeBeta.js";
|
|
@@ -87,16 +86,10 @@ const Header = ({
|
|
|
87
86
|
] }),
|
|
88
87
|
/* @__PURE__ */ jsxs(NavItem, { className: "position-relative", ref: userRef, id: popoverUserId, "aria-haspopup": "true", "aria-expanded": isUserHovered, "data-testid": "header-user-menu-button", children: [
|
|
89
88
|
/* @__PURE__ */ jsx(NavLink, { link: "/userbook/mon-compte", translate: t("navbar.myaccount"), "data-testid": "header-user-profile-button", children: /* @__PURE__ */ jsx(Avatar, { alt: userName, size: "sm", src: userAvatar, variant: "circle", className: "bg-white", width: "32", height: "32" }) }),
|
|
90
|
-
/* @__PURE__ */ jsx(Popover, { align: "end", className: "widget", id: popoverUserId, isVisible: isUserHovered, children: /* @__PURE__ */
|
|
91
|
-
/* @__PURE__ */
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
] }),
|
|
95
|
-
/* @__PURE__ */ jsxs("a", { href: "/auth/logout?callback=" + ((theme == null ? void 0 : theme.logoutCallback) ?? ""), className: "nav-link logout d-flex align-items-center gap-8", "data-testid": "header-logout-button", children: [
|
|
96
|
-
/* @__PURE__ */ jsx(SvgIconDisconnect, { className: "icon logout" }),
|
|
97
|
-
/* @__PURE__ */ jsx("span", { id: "logout-label", className: "nav-text", children: t("navbar.disconnect") })
|
|
98
|
-
] })
|
|
99
|
-
] }) })
|
|
89
|
+
/* @__PURE__ */ jsx(Popover, { align: "end", className: "widget", id: popoverUserId, isVisible: isUserHovered, children: /* @__PURE__ */ jsx(PopoverBody, { children: /* @__PURE__ */ jsxs("a", { href: "/auth/logout?callback=" + ((theme == null ? void 0 : theme.logoutCallback) ?? ""), className: "nav-link logout d-flex align-items-center gap-8", "data-testid": "header-logout-button", children: [
|
|
90
|
+
/* @__PURE__ */ jsx(SvgIconDisconnect, { className: "icon logout" }),
|
|
91
|
+
/* @__PURE__ */ jsx("span", { id: "logout-label", className: "nav-text", children: t("navbar.disconnect") })
|
|
92
|
+
] }) }) })
|
|
100
93
|
] })
|
|
101
94
|
] })
|
|
102
95
|
] }) });
|
|
@@ -17,20 +17,18 @@ function useProfileLinks(profile) {
|
|
|
17
17
|
structure: structureId
|
|
18
18
|
});
|
|
19
19
|
return `${baseUrl}?${params.toString()}`;
|
|
20
|
-
}, buildClassesUrl = (
|
|
21
|
-
const params = new URLSearchParams(
|
|
20
|
+
}, buildClassesUrl = (classIds = []) => {
|
|
21
|
+
const params = new URLSearchParams({
|
|
22
|
+
filters: "groups",
|
|
23
|
+
structure: structureId
|
|
24
|
+
});
|
|
22
25
|
return classIds.forEach((c) => params.append("class", String(c))), `${baseUrl}?${params.toString()}`;
|
|
23
26
|
};
|
|
24
27
|
switch (profile) {
|
|
25
28
|
case "Teacher":
|
|
26
29
|
return [{
|
|
27
30
|
text: t("homepage.userspace.teacher.link.classes"),
|
|
28
|
-
url: buildClassesUrl(
|
|
29
|
-
{
|
|
30
|
-
filters: "groups"
|
|
31
|
-
}
|
|
32
|
-
/* Do not explicitely add classes ids, because none <=> see all*/
|
|
33
|
-
)
|
|
31
|
+
url: buildClassesUrl(user.classes)
|
|
34
32
|
}];
|
|
35
33
|
case "Student":
|
|
36
34
|
return [{
|
|
@@ -38,12 +36,7 @@ function useProfileLinks(profile) {
|
|
|
38
36
|
url: "/userbook/annuaire#/search?filters=groups&profile=Teacher"
|
|
39
37
|
}, {
|
|
40
38
|
text: t("homepage.userspace.student.link.classes"),
|
|
41
|
-
url: buildClassesUrl(
|
|
42
|
-
{
|
|
43
|
-
filters: "groups"
|
|
44
|
-
}
|
|
45
|
-
/* Do not explicitely add classes ids, because none <=> see all*/
|
|
46
|
-
)
|
|
39
|
+
url: buildClassesUrl(user.classes)
|
|
47
40
|
}];
|
|
48
41
|
case "Relative":
|
|
49
42
|
return children != null && children.length ? children.map((child) => {
|
|
@@ -52,10 +45,7 @@ function useProfileLinks(profile) {
|
|
|
52
45
|
text: t("homepage.userspace.relative.link.classes", {
|
|
53
46
|
childName: child.firstName
|
|
54
47
|
}),
|
|
55
|
-
url: buildClassesUrl({
|
|
56
|
-
filters: "groups",
|
|
57
|
-
structure: structureId
|
|
58
|
-
}, (_a2 = child.classes) == null ? void 0 : _a2.map(({
|
|
48
|
+
url: buildClassesUrl((_a2 = child.classes) == null ? void 0 : _a2.map(({
|
|
59
49
|
id
|
|
60
50
|
}) => id))
|
|
61
51
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
3
|
import { useTranslation } from "react-i18next";
|
|
4
|
-
import
|
|
4
|
+
import { useMediaLibraryContext } from "../MediaLibraryContext.js";
|
|
5
|
+
import Flex from "../../../../components/Flex/Flex.js";
|
|
6
|
+
import Radio from "../../../../components/Radio/Radio.js";
|
|
5
7
|
import Dropzone from "../../../../components/Dropzone/Dropzone.js";
|
|
6
8
|
import UploadFiles from "../../UploadFiles/UploadFiles.js";
|
|
7
9
|
const acceptedTypes = (type) => {
|
|
@@ -18,6 +20,17 @@ const acceptedTypes = (type) => {
|
|
|
18
20
|
break;
|
|
19
21
|
}
|
|
20
22
|
return acceptedTypes2;
|
|
23
|
+
}, orderUploadedFiles = (uploadedFiles, sourceFilesInfo, byAlpha) => {
|
|
24
|
+
const infoOf = (element) => element._id ? sourceFilesInfo[element._id] : void 0, nameOf = (element) => {
|
|
25
|
+
var _a;
|
|
26
|
+
return ((_a = infoOf(element)) == null ? void 0 : _a.name) ?? element.name;
|
|
27
|
+
}, lastModifiedOf = (element) => {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = infoOf(element)) == null ? void 0 : _a.lastModified) ?? 0;
|
|
30
|
+
};
|
|
31
|
+
return byAlpha ? [...uploadedFiles].sort((a, b) => nameOf(a).localeCompare(nameOf(b), void 0, {
|
|
32
|
+
numeric: !0
|
|
33
|
+
})) : [...uploadedFiles].sort((a, b) => lastModifiedOf(b) - lastModifiedOf(a)).reverse();
|
|
21
34
|
}, Upload = () => {
|
|
22
35
|
const {
|
|
23
36
|
t
|
|
@@ -27,12 +40,26 @@ const acceptedTypes = (type) => {
|
|
|
27
40
|
multiple,
|
|
28
41
|
setResult,
|
|
29
42
|
setResultCounter,
|
|
30
|
-
setCancellable
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
setCancellable,
|
|
44
|
+
setPreSuccess
|
|
45
|
+
} = useMediaLibraryContext(), [sortByAlpha, setSortByAlpha] = useState(!0), [uploadedFiles, setUploadedFiles] = useState([]), sourceFilesInfoRef = useRef({}), handleOnFilesChange = (uploadedFiles2, sourceFilesInfo) => {
|
|
46
|
+
sourceFilesInfoRef.current = sourceFilesInfo, setUploadedFiles(uploadedFiles2), uploadedFiles2.length ? (setCancellable(uploadedFiles2), setResultCounter(uploadedFiles2.length), setResult(uploadedFiles2)) : (setCancellable([]), setResultCounter(void 0), setResult(void 0));
|
|
33
47
|
};
|
|
34
|
-
return
|
|
35
|
-
|
|
48
|
+
return useEffect(() => {
|
|
49
|
+
if (!multiple || !uploadedFiles.length) {
|
|
50
|
+
setPreSuccess(void 0);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setPreSuccess(() => () => Promise.resolve(orderUploadedFiles(uploadedFiles, sourceFilesInfoRef.current, sortByAlpha)));
|
|
54
|
+
}, [multiple, uploadedFiles, sortByAlpha, setPreSuccess]), /* @__PURE__ */ jsxs("div", { className: "flex-grow-1", children: [
|
|
55
|
+
multiple && /* @__PURE__ */ jsxs(Flex, { className: "mb-16 ms-8", align: "start", direction: "column", gap: "8", children: [
|
|
56
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
57
|
+
t("bbm.upload.sort.title"),
|
|
58
|
+
" :"
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsx(Radio, { label: t("bbm.upload.sort.alpha"), name: "media-library-upload-sort", value: "alpha", model: sortByAlpha ? "alpha" : "date", checked: sortByAlpha, onChange: () => setSortByAlpha(!0), "data-testid": "media-library-upload-sort-alpha" }),
|
|
61
|
+
/* @__PURE__ */ jsx(Radio, { label: t("bbm.upload.sort.date"), name: "media-library-upload-sort", value: "date", model: sortByAlpha ? "alpha" : "date", checked: !sortByAlpha, onChange: () => setSortByAlpha(!1), "data-testid": "media-library-upload-sort-date" })
|
|
62
|
+
] }),
|
|
36
63
|
/* @__PURE__ */ jsx(Dropzone, { multiple, accept: acceptedTypes(type ?? "embedder"), children: /* @__PURE__ */ jsx(UploadFiles, { onFilesChange: handleOnFilesChange, visibility }) })
|
|
37
64
|
] });
|
|
38
65
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { WorkspaceElement, WorkspaceVisibility } from '@edifice.io/client';
|
|
2
|
+
import { UploadSourceFileInfo } from '../../../hooks';
|
|
2
3
|
declare const UploadFiles: {
|
|
3
4
|
({ onFilesChange, visibility, }: {
|
|
4
|
-
onFilesChange: (uploadedFiles: WorkspaceElement[]) => void;
|
|
5
|
+
onFilesChange: (uploadedFiles: WorkspaceElement[], sourceFilesInfo: Record<string, UploadSourceFileInfo>) => void;
|
|
5
6
|
visibility?: WorkspaceVisibility;
|
|
6
7
|
}): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
displayName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edifice.io/react",
|
|
3
|
-
"version": "2.6.5-develop-
|
|
3
|
+
"version": "2.6.5-develop-pedago.20260909143307",
|
|
4
4
|
"description": "Edifice React Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -140,9 +140,9 @@
|
|
|
140
140
|
"swiper": "10.1.0",
|
|
141
141
|
"ua-parser-js": "1.0.36",
|
|
142
142
|
"zustand": "4.5.7",
|
|
143
|
-
"@edifice.io/bootstrap": "2.6.5-develop-
|
|
144
|
-
"@edifice.io/tiptap-extensions": "2.6.5-develop-
|
|
145
|
-
"@edifice.io/utilities": "2.6.5-develop-
|
|
143
|
+
"@edifice.io/bootstrap": "2.6.5-develop-pedago.20260909143307",
|
|
144
|
+
"@edifice.io/tiptap-extensions": "2.6.5-develop-pedago.20260909143307",
|
|
145
|
+
"@edifice.io/utilities": "2.6.5-develop-pedago.20260909143307"
|
|
146
146
|
},
|
|
147
147
|
"devDependencies": {
|
|
148
148
|
"@babel/plugin-transform-react-pure-annotations": "7.27.1",
|
|
@@ -173,8 +173,8 @@
|
|
|
173
173
|
"vite": "5.4.14",
|
|
174
174
|
"vite-plugin-dts": "4.5.4",
|
|
175
175
|
"vite-tsconfig-paths": "5.1.4",
|
|
176
|
-
"@edifice.io/
|
|
177
|
-
"@edifice.io/
|
|
176
|
+
"@edifice.io/client": "2.6.5-develop-pedago.20260909143307",
|
|
177
|
+
"@edifice.io/config": "2.6.5-develop-pedago.20260909143307"
|
|
178
178
|
},
|
|
179
179
|
"peerDependencies": {
|
|
180
180
|
"@react-spring/web": "9.7.5",
|