Add toolbox spaces and recover from stale asset bundles
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
0959c6740b
commit
0acf5ecf21
30 changed files with 1252 additions and 179 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Rôle : affiche les pages toolbox, le panneau latéral et leurs contrôles.
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { GuidedTooltipTour } from "../../components/GuidedTooltipTour.jsx";
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
import { ImportButton } from "../../components/ImportButton.jsx";
|
||||
|
|
@ -11,6 +11,16 @@ import { useInlineEdit } from "../../hooks/useInlineEdit.js";
|
|||
import { compressImage } from "../../utils/imageCompression.js";
|
||||
import { getGameCardCover, ToolboxCard, ToolboxGameIcon, ToolboxIconPicker } from "./ToolboxCard.jsx";
|
||||
import { AddToolControls, ToolboxModules } from "./modules/index.jsx";
|
||||
import { ToolboxSpaces } from "./ToolboxSpaces.jsx";
|
||||
import {
|
||||
addModuleToToolboxSpace,
|
||||
decodeSpaceColumn,
|
||||
encodeSpaceColumn,
|
||||
getActiveToolboxSpace,
|
||||
getModuleSpace,
|
||||
moveToolboxModule,
|
||||
removeModuleFromToolboxSpaces
|
||||
} from "./toolboxSpaceUtils.js";
|
||||
import {
|
||||
clampQty,
|
||||
hostnameFromUrl,
|
||||
|
|
@ -24,7 +34,6 @@ import {
|
|||
normalizeImageAnnotationData,
|
||||
normalizeLinksData,
|
||||
normalizeMemosData,
|
||||
normalizeModuleOrder,
|
||||
normalizeNotepadData,
|
||||
normalizeRandomizerData,
|
||||
normalizeRngSimulatorData,
|
||||
|
|
@ -42,31 +51,6 @@ function getDrawerMaxWidth() {
|
|||
return Math.max(DRAWER_INITIAL_WIDTH, Math.floor(window.innerWidth * 0.94));
|
||||
}
|
||||
|
||||
function addModuleToOrder(moduleOrder, modules, moduleId) {
|
||||
const order = normalizeModuleOrder(moduleOrder, modules);
|
||||
const two = [
|
||||
order.two[0].filter((id) => id !== moduleId),
|
||||
order.two[1].filter((id) => id !== moduleId)
|
||||
];
|
||||
const targetColumnIndex = two[0].length <= two[1].length ? 0 : 1;
|
||||
two[targetColumnIndex].push(moduleId);
|
||||
return {
|
||||
one: [...order.one.filter((id) => id !== moduleId), moduleId],
|
||||
two
|
||||
};
|
||||
}
|
||||
|
||||
function removeModuleFromOrder(moduleOrder, modules, moduleId) {
|
||||
const order = normalizeModuleOrder(moduleOrder, modules);
|
||||
return {
|
||||
one: order.one.filter((id) => id !== moduleId),
|
||||
two: [
|
||||
order.two[0].filter((id) => id !== moduleId),
|
||||
order.two[1].filter((id) => id !== moduleId)
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
async function copyText(value) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
|
|
@ -187,10 +171,16 @@ function shouldShowTutorial(toolbox, pendingTutorialToolboxId) {
|
|||
function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, storageUsage, storageReady = true, getModuleData, updateToolbox, updateModuleData, addImageFiles, pendingTutorialToolboxId = "", setPendingTutorialToolboxId, guideChecklist }) {
|
||||
const toolboxId = toolbox.id;
|
||||
const moduleColumns = embedded || Number(toolbox.moduleColumns) === 1 ? 1 : 2;
|
||||
const activeSpace = getActiveToolboxSpace(toolbox);
|
||||
const spacesText = siteContent.toolboxes.spaces;
|
||||
const toolboxGameCover = getGameCardCover(toolboxGame);
|
||||
const moduleText = siteContent.toolboxes.modules;
|
||||
const [showTutorial, setShowTutorial] = useState(() => shouldShowTutorial(toolbox, pendingTutorialToolboxId));
|
||||
const [pendingModuleId, setPendingModuleId] = useState("");
|
||||
const dragOriginSpaceRef = useRef("");
|
||||
const dragSucceededRef = useRef(false);
|
||||
const hoverActivatedRef = useRef(false);
|
||||
const previousDraggingIdRef = useRef("");
|
||||
const tutorialRequested = shouldShowTutorial(toolbox, pendingTutorialToolboxId);
|
||||
const [previousTutorial, setPreviousTutorial] = useState({ toolboxId, requested: tutorialRequested });
|
||||
// Consommer la demande de lancement ne doit pas interrompre la visite en cours.
|
||||
|
|
@ -237,15 +227,99 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
|
|||
refresh: () => {}
|
||||
};
|
||||
|
||||
const moduleLocations = useMemo(() => {
|
||||
const locations = new Map();
|
||||
toolbox.spaces.forEach((space) => {
|
||||
space.moduleOrder.one.forEach((moduleId) => {
|
||||
const column = space.moduleOrder.two[1].includes(moduleId) ? "right" : "left";
|
||||
locations.set(moduleId, { spaceId: space.id, column });
|
||||
});
|
||||
});
|
||||
return locations;
|
||||
}, [toolbox.spaces]);
|
||||
|
||||
const rawModuleReorder = useGroupedReorder({
|
||||
namespace: `toolbox-modules-${toolbox.id}`,
|
||||
items: toolbox.modules,
|
||||
getItemId: (module) => module.id,
|
||||
getItemGroup: (module) => {
|
||||
const location = moduleLocations.get(module.id);
|
||||
return encodeSpaceColumn(location?.spaceId || toolbox.defaultSpaceId, moduleColumns === 1 ? "one" : location?.column || "left");
|
||||
},
|
||||
getEffectiveGroup: (module) => {
|
||||
const location = moduleLocations.get(module.id);
|
||||
return encodeSpaceColumn(location?.spaceId || toolbox.defaultSpaceId, moduleColumns === 1 ? "one" : location?.column || "left");
|
||||
},
|
||||
getParentId: () => toolbox.id,
|
||||
reorderFeatures: { item: { groupChange: true, boundaryDrop: true } },
|
||||
canMoveItem: (operation) => operation.targetType !== "group" || decodeSpaceColumn(operation.sourceGroup).spaceId !== operation.targetGroup,
|
||||
onItemMove: (operation) => {
|
||||
let targetSpaceId = "";
|
||||
let targetColumn = "";
|
||||
let targetModuleId = "";
|
||||
if (operation.targetType === "group") {
|
||||
targetSpaceId = operation.targetGroup;
|
||||
} else if (operation.targetType === "item") {
|
||||
targetModuleId = operation.targetId;
|
||||
targetSpaceId = getModuleSpace(toolbox, targetModuleId)?.id || "";
|
||||
} else if (operation.targetType === "boundary") {
|
||||
const target = decodeSpaceColumn(operation.targetGroup);
|
||||
targetSpaceId = target.spaceId;
|
||||
targetColumn = target.column;
|
||||
}
|
||||
if (!targetSpaceId) return;
|
||||
const sourceSpace = getModuleSpace(toolbox, operation.sourceId);
|
||||
dragSucceededRef.current = true;
|
||||
updateToolbox(moveToolboxModule(toolbox, operation.sourceId, {
|
||||
targetSpaceId,
|
||||
targetModuleId,
|
||||
targetColumn,
|
||||
placement: operation.placement,
|
||||
moduleColumns
|
||||
}));
|
||||
if (sourceSpace?.id !== targetSpaceId) {
|
||||
const destination = toolbox.spaces.find((space) => space.id === targetSpaceId);
|
||||
actions.notify(spacesText.moveSuccess.replace("{space}", destination?.name || ""));
|
||||
}
|
||||
},
|
||||
hierarchy: { enabled: true, stickyParents: true }
|
||||
});
|
||||
const moduleReorder = {
|
||||
...rawModuleReorder,
|
||||
itemReorder: {
|
||||
...rawModuleReorder.itemReorder,
|
||||
startDrag: (event, moduleId) => {
|
||||
dragOriginSpaceRef.current = getModuleSpace(toolbox, moduleId)?.id || activeSpace.id;
|
||||
dragSucceededRef.current = false;
|
||||
hoverActivatedRef.current = false;
|
||||
rawModuleReorder.itemReorder.startDrag(event, moduleId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const activateHoveredSpace = useCallback((spaceId) => {
|
||||
if (spaceId === toolbox.activeSpaceId) return;
|
||||
hoverActivatedRef.current = true;
|
||||
updateToolbox({ ...toolbox, activeSpaceId: spaceId });
|
||||
}, [toolbox, updateToolbox]);
|
||||
|
||||
useEffect(() => {
|
||||
const draggingId = rawModuleReorder.itemReorder.draggingId;
|
||||
if (previousDraggingIdRef.current && !draggingId) {
|
||||
if (!dragSucceededRef.current && hoverActivatedRef.current && toolbox.spaces.some((space) => space.id === dragOriginSpaceRef.current)) {
|
||||
updateToolbox({ ...toolbox, activeSpaceId: dragOriginSpaceRef.current });
|
||||
}
|
||||
dragOriginSpaceRef.current = "";
|
||||
dragSucceededRef.current = false;
|
||||
hoverActivatedRef.current = false;
|
||||
}
|
||||
previousDraggingIdRef.current = draggingId;
|
||||
}, [rawModuleReorder.itemReorder.draggingId, toolbox, updateToolbox]);
|
||||
|
||||
function addModule(type, initialData = null) {
|
||||
if (!type) return;
|
||||
const module = { id: uid("mod"), type };
|
||||
const modules = [...toolbox.modules, module];
|
||||
updateToolbox({
|
||||
...toolbox,
|
||||
modules,
|
||||
moduleOrder: addModuleToOrder(toolbox.moduleOrder, modules, module.id)
|
||||
});
|
||||
updateToolbox(addModuleToToolboxSpace(toolbox, module, activeSpace.id));
|
||||
setPendingModuleId(module.id);
|
||||
if (initialData) updateModuleData(toolbox.id, module.id, initialData, type);
|
||||
}
|
||||
|
|
@ -253,12 +327,7 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
|
|||
function createImageAnnotationModule(dataUrl) {
|
||||
if (!dataUrl) return;
|
||||
const moduleId = uid("mod");
|
||||
const modules = [...toolbox.modules, { id: moduleId, type: "imageAnnotation" }];
|
||||
updateToolbox({
|
||||
...toolbox,
|
||||
modules,
|
||||
moduleOrder: addModuleToOrder(toolbox.moduleOrder, modules, moduleId)
|
||||
});
|
||||
updateToolbox(addModuleToToolboxSpace(toolbox, { id: moduleId, type: "imageAnnotation" }, activeSpace.id));
|
||||
setPendingModuleId(moduleId);
|
||||
updateModuleData(toolbox.id, moduleId, { image: dataUrl, markers: [] }, "imageAnnotation");
|
||||
}
|
||||
|
|
@ -291,6 +360,14 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
|
|||
<AddToolControls onAdd={addModule} />
|
||||
</div>
|
||||
</section>
|
||||
<ToolboxSpaces
|
||||
toolbox={toolbox}
|
||||
text={spacesText}
|
||||
moduleReorder={moduleReorder}
|
||||
onUpdateToolbox={updateToolbox}
|
||||
onHoverActivate={activateHoveredSpace}
|
||||
onConfirm={actions.setConfirmModal}
|
||||
/>
|
||||
{!embedded && showTutorial && (
|
||||
<GuidedTooltipTour
|
||||
key={toolboxId}
|
||||
|
|
@ -321,13 +398,20 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
|
|||
)}
|
||||
<ToolboxModules
|
||||
toolbox={toolbox}
|
||||
space={activeSpace}
|
||||
moduleColumns={moduleColumns}
|
||||
context={moduleContext}
|
||||
reorder={moduleReorder}
|
||||
spacesText={spacesText}
|
||||
scrollToModuleId={pendingModuleId}
|
||||
onModuleScrolled={() => setPendingModuleId("")}
|
||||
onRename={(moduleId, title) => updateToolbox({ ...toolbox, modules: toolbox.modules.map((module) => module.id === moduleId ? { ...module, title } : module) })}
|
||||
onUpdateModule={(moduleId, updater) => updateToolbox({ ...toolbox, modules: toolbox.modules.map((module) => module.id === moduleId ? updater(module) : module) })}
|
||||
onModuleOrderChange={(moduleOrder) => updateToolbox({ ...toolbox, moduleOrder })}
|
||||
onMoveToSpace={(moduleId, targetSpaceId) => {
|
||||
const destination = toolbox.spaces.find((space) => space.id === targetSpaceId);
|
||||
updateToolbox(moveToolboxModule(toolbox, moduleId, { targetSpaceId, moduleColumns }));
|
||||
actions.notify(spacesText.moveSuccess.replace("{space}", destination?.name || ""));
|
||||
}}
|
||||
onDelete={(moduleId) => actions.setConfirmModal({
|
||||
title: "Retirer l'outil",
|
||||
message: "Retirer cet outil de la toolbox ?",
|
||||
|
|
@ -336,12 +420,7 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
|
|||
onResolve: (confirmed) => {
|
||||
if (!confirmed) return;
|
||||
actions.removeModuleData(toolbox.id, moduleId);
|
||||
const modules = toolbox.modules.filter((module) => module.id !== moduleId);
|
||||
updateToolbox({
|
||||
...toolbox,
|
||||
modules,
|
||||
moduleOrder: removeModuleFromOrder(toolbox.moduleOrder, modules, moduleId)
|
||||
});
|
||||
updateToolbox(removeModuleFromToolboxSpaces(toolbox, moduleId));
|
||||
}
|
||||
})}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue