Split dailyShare.js and document the shared exported functions with JSDoc
dailyShare.js held fillTemplate and formatCountdown, used across the whole TCG, under a Daily Card name. They now live in textFormat.js at the root, and the Daily Card helpers in daily/dailyFormat.js. 173 exported functions that other files call now explain what they return and how they treat missing values: the server game rules, the toolbox storage chain, the shared hooks and utilities, and the TCG display helpers. website/AGENTS.md asks the same of new shared functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
166790245f
commit
aa8bb1ebaa
71 changed files with 339 additions and 57 deletions
|
|
@ -122,18 +122,24 @@ const TEXT_EXCHANGE_HANDLERS = {
|
|||
}
|
||||
};
|
||||
|
||||
/** Vrai si ce type d'outil sait s'exporter et s'importer en texte. */
|
||||
export function supportsTextExchange(type) {
|
||||
return Boolean(TEXT_EXCHANGE_HANDLERS[type]);
|
||||
}
|
||||
|
||||
/** Vrai si les données de l'outil ont quelque chose à exporter en texte. */
|
||||
export function hasTextExchangeContent(type, data) {
|
||||
return Boolean(TEXT_EXCHANGE_HANDLERS[type]?.hasContent(data));
|
||||
}
|
||||
|
||||
/** Texte d'export de l'outil, ou chaîne vide si le type ne le gère pas. */
|
||||
export function exportModuleText(type, data) {
|
||||
return TEXT_EXCHANGE_HANDLERS[type]?.exportText(data) || "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un texte collé pour un outil : `{ ok: true, data }`, ou `{ ok: false, error }` avec un message pour l'utilisateur. Ne lève jamais.
|
||||
*/
|
||||
export function importModuleText(type, text, context) {
|
||||
try {
|
||||
const value = String(text || "");
|
||||
|
|
|
|||
|
|
@ -4,14 +4,17 @@
|
|||
|
||||
const MIB = 1024 * 1024;
|
||||
|
||||
/** Remplace chaque `{clé}` connue ; une clé absente de `values` reste écrite telle quelle. */
|
||||
export function fillTemplate(text, values = {}) {
|
||||
return String(text || "").replace(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match));
|
||||
}
|
||||
|
||||
/** Date et heure en français, format moyen (« 3 déc. 2026, 14:05 »). */
|
||||
export function formatShareDate(value) {
|
||||
return new Intl.DateTimeFormat("fr-FR", { dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
|
||||
}
|
||||
|
||||
/** Taille en Mio, avec une décimale au plus. */
|
||||
export function formatMiB(bytes) {
|
||||
return new Intl.NumberFormat("fr-FR", { maximumFractionDigits: 1 }).format(bytes / MIB);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ async function failedResponse(response) {
|
|||
return apiError(response.status, await response.json().catch(() => null));
|
||||
}
|
||||
|
||||
/** Réglages publics des partages : `enabled`, taille maximale (`maxBytes`) et durée de vie (`ttlMs`). */
|
||||
export async function loadSharesConfig() {
|
||||
const response = await fetch("/api/shares/config", { headers: { Accept: "application/json" } });
|
||||
if (!response.ok) throw await failedResponse(response);
|
||||
|
|
@ -39,12 +40,14 @@ export function uploadShare(bytes, { singleUse = true, onProgress } = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
/** Taille et date d'expiration d'un partage, sans le télécharger. */
|
||||
export async function loadShareMeta(id) {
|
||||
const response = await fetch(`/api/shares/${encodeURIComponent(id)}/meta`, { headers: { Accept: "application/json" } });
|
||||
if (!response.ok) throw await failedResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/** Télécharge le contenu chiffré d'un partage ; `onProgress` reçoit l'avancement. Un partage à usage unique n'est plus lisible ensuite. */
|
||||
export async function downloadShare(id, { onProgress } = {}) {
|
||||
const response = await fetch(`/api/shares/${encodeURIComponent(id)}`);
|
||||
if (!response.ok) throw await failedResponse(response);
|
||||
|
|
|
|||
|
|
@ -22,10 +22,15 @@ export class ShareLimitError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
/** Lien de réception d'un partage. La clé est après le second `#` : le navigateur ne l'envoie jamais au serveur. */
|
||||
export function shareLink(id, key, origin = globalThis.location?.origin || "") {
|
||||
return `${origin}/#/receive/${id}#${key}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chiffre et envoie une toolbox, puis enregistre le partage dans le quota local. Renvoie le partage actif existant de cette
|
||||
* toolbox s'il y en a un. Lève `ShareLimitError` (quota, taille) ; `onStage` suit la préparation et l'envoi.
|
||||
*/
|
||||
export async function createToolboxShare({ toolboxId, buildPayload, maxBytes, singleUse = true, onStage, quota = createShareQuota() }) {
|
||||
const existing = quota.activeShareFor(toolboxId);
|
||||
if (existing) return existing;
|
||||
|
|
@ -53,6 +58,7 @@ export async function createToolboxShare({ toolboxId, buildPayload, maxBytes, si
|
|||
}, bytes.length);
|
||||
}
|
||||
|
||||
/** Supprime un partage sur le serveur (avec son jeton de suppression) et l'oublie localement. */
|
||||
export async function revokeToolboxShare(shareId, quota = createShareQuota()) {
|
||||
const entry = quota.activeShares().find((item) => item.id === shareId);
|
||||
if (!entry) return;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@
|
|||
|
||||
export const DEFERRED_MODULE_DATA = Symbol("deferred module data");
|
||||
|
||||
/** Clés des outils dont les données sont des médias (Images, Annotation d'image), lues à la demande et pas au démarrage. */
|
||||
export function getDeferredModuleKeys(toolboxes) {
|
||||
return toolboxes.flatMap((toolbox) => (toolbox.modules || [])
|
||||
.filter((module) => module.type === "images" || module.type === "imageAnnotation")
|
||||
.map((module) => `${toolbox.id}:${module.id}`));
|
||||
}
|
||||
|
||||
/** Sépare les données chargées (`stored`) des clés encore marquées `DEFERRED_MODULE_DATA` (`deferred`). */
|
||||
export function splitModuleData(moduleData) {
|
||||
const stored = {};
|
||||
const deferred = [];
|
||||
|
|
@ -21,6 +23,10 @@ export function splitModuleData(moduleData) {
|
|||
return { stored, deferred };
|
||||
}
|
||||
|
||||
/**
|
||||
* Remplace les marqueurs `DEFERRED_MODULE_DATA` par les données lues ; une clé lue mais absente de la base est retirée.
|
||||
* Une clé supprimée entre-temps (plus marquée) n'est pas ressuscitée.
|
||||
*/
|
||||
export function mergeLoadedModuleData(moduleData, keys, entries) {
|
||||
const next = { ...moduleData };
|
||||
const loaded = new Map(entries.map((entry) => [entry.key, entry.data]));
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// Formats bitmap uniquement : un SVG ou un document HTML exécuterait ses scripts sur l'origine du site une fois ouvert.
|
||||
const SAFE_IMAGE_DATA_URL = /^data:image\/(?:jpeg|jpg|png|webp|gif|avif);base64,[a-z0-9+/]+=*$/i;
|
||||
|
||||
/** Vrai pour une image bitmap en data URL (JPEG, PNG, WebP, GIF, AVIF) ; un SVG est refusé. */
|
||||
export function isSafeImageDataUrl(value) {
|
||||
return typeof value === "string" && SAFE_IMAGE_DATA_URL.test(value);
|
||||
}
|
||||
|
|
@ -54,15 +55,18 @@ function randomToken(length = 6) {
|
|||
return Math.random().toString(36).slice(2, 2 + length).padEnd(length, "0");
|
||||
}
|
||||
|
||||
/** Nouvel identifiant aléatoire, préfixé d'une lettre selon le type d'objet : `uid("tbx")`, `uid("mod")`, `uid("space")`… */
|
||||
export function uid(prefix) {
|
||||
return `${ID_PREFIXES[prefix] || "x"}${randomToken()}`;
|
||||
}
|
||||
|
||||
/** Entier strictement positif lu dans la valeur, ou `fallback`. */
|
||||
export function parsePositiveInt(value, fallback = 1) {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
||||
}
|
||||
|
||||
/** Date ISO 8601 complète si la valeur est une date lisible, sinon chaîne vide. */
|
||||
export function normalizeIsoDate(value) {
|
||||
const text = String(value || "").trim();
|
||||
if (!text) return "";
|
||||
|
|
@ -70,6 +74,7 @@ export function normalizeIsoDate(value) {
|
|||
return Number.isFinite(timestamp) ? new Date(timestamp).toISOString() : "";
|
||||
}
|
||||
|
||||
/** Horodatage en millisecondes s'il est positif, sinon 0. */
|
||||
export function normalizeTimestamp(value) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
* @file Applique les changements immuables de données de modules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copie des données d'outils avec la valeur de `key` remplacée ; `null` ou `undefined` retire la clé. Affichée avant la fin de l'écriture.
|
||||
*/
|
||||
export function applyModuleDataValue(moduleData, key, value) {
|
||||
const nextModuleData = { ...moduleData };
|
||||
if (value == null) delete nextModuleData[key];
|
||||
|
|
@ -9,6 +12,7 @@ export function applyModuleDataValue(moduleData, key, value) {
|
|||
return nextModuleData;
|
||||
}
|
||||
|
||||
/** Copie des données d'outils sans les clés données. */
|
||||
export function removeModuleDataKeys(moduleData, keys) {
|
||||
const nextModuleData = { ...moduleData };
|
||||
for (const key of keys) delete nextModuleData[key];
|
||||
|
|
|
|||
|
|
@ -55,6 +55,11 @@ function toolboxChanges(expected, next) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Différence entre l'état attendu en base et l'état voulu : toolboxes, associations et données d'outils changées, avec la valeur
|
||||
* attendue de chacune. `changed` est faux s'il n'y a rien à écrire. Les médias pas encore lus (`DEFERRED_MODULE_DATA`) ne sont jamais
|
||||
* réécrits.
|
||||
*/
|
||||
export function createStorageMutation(expected, next) {
|
||||
const toolboxes = toolboxChanges(expected.toolboxes, next.toolboxes);
|
||||
const links = keyedChanges(expected.links, next.links);
|
||||
|
|
@ -67,6 +72,7 @@ export function createStorageMutation(expected, next) {
|
|||
};
|
||||
}
|
||||
|
||||
/** Résumé d'une écriture envoyé aux autres onglets (BroadcastChannel) : ce qu'ils doivent relire. */
|
||||
export function getStorageMutationNotice(mutation) {
|
||||
return {
|
||||
registry: Boolean(mutation.toolboxes.changes.length || mutation.toolboxes.order),
|
||||
|
|
|
|||
|
|
@ -67,12 +67,14 @@ export const DEFAULT_TOOLBOX_ICON = `${TOOLBOX_ICON_BASE}toolbox.webp`;
|
|||
export const MAX_TOOLBOX_SPACES = 5;
|
||||
const LEGACY_TOOLBOX_UPDATED_AT = "1970-01-01T00:00:00.000Z";
|
||||
|
||||
/** Chemin d'une icône connue de toolbox (ancien `.png` accepté), ou l'icône par défaut si elle est inconnue. */
|
||||
export function normalizeToolboxIcon(icon) {
|
||||
const value = String(icon || "").trim();
|
||||
const file = value.replace(TOOLBOX_ICON_BASE, "").split("/").pop().replace(/\.png$/i, ".webp");
|
||||
return TOOLBOX_ICON_FILES.includes(file) ? `${TOOLBOX_ICON_BASE}${file}` : DEFAULT_TOOLBOX_ICON;
|
||||
}
|
||||
|
||||
/** Image de couverture personnalisée si c'est une image JPEG, PNG ou WebP en data URL, sinon chaîne vide. */
|
||||
export function normalizeToolboxCustomCover(customCover) {
|
||||
const value = String(customCover || "").trim();
|
||||
return /^data:image\/(?:jpeg|jpg|png|webp);base64,[a-z0-9+/]+=*$/i.test(value) ? value : "";
|
||||
|
|
@ -111,6 +113,10 @@ function splitModuleOrder(ids) {
|
|||
return [ids.slice(0, splitIndex), ids.slice(splitIndex)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ordre d'affichage complet des outils, en une colonne (`one`) et en deux colonnes (`two`) : ids inconnus ou en double retirés,
|
||||
* outils manquants ajoutés à la fin (dans la colonne la plus courte).
|
||||
*/
|
||||
export function normalizeModuleOrder(moduleOrder, modules) {
|
||||
const moduleIds = modules.map((module) => module.id);
|
||||
const one = completeModuleOrder(moduleOrder?.one, moduleIds);
|
||||
|
|
@ -130,6 +136,7 @@ export function normalizeModuleOrder(moduleOrder, modules) {
|
|||
return { one, two };
|
||||
}
|
||||
|
||||
/** Ordre des outils avec chaque id remplacé par `moduleIdMap` (copie ou import de toolbox) ; les ids sans correspondance sont retirés. */
|
||||
export function remapModuleOrderIds(moduleOrder, moduleIdMap) {
|
||||
if (!moduleOrder) return null;
|
||||
const remapIds = (ids) => (Array.isArray(ids) ? ids.map((id) => moduleIdMap.get(id)).filter(Boolean) : []);
|
||||
|
|
@ -151,6 +158,10 @@ function getSpaceModuleIds(space, knownModuleIds) {
|
|||
return uniqueKnownIds(candidates, knownModuleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Espaces valides d'une toolbox, avec l'espace par défaut et l'espace actif. Une ancienne toolbox sans espaces reçoit un espace
|
||||
* « Défaut » d'identifiant fixe.
|
||||
*/
|
||||
export function normalizeToolboxSpaces(toolbox, modules) {
|
||||
const moduleIds = modules.map((module) => module.id);
|
||||
const rawSpaces = Array.isArray(toolbox?.spaces) ? toolbox.spaces.filter((space) => space && typeof space === "object") : [];
|
||||
|
|
@ -208,6 +219,10 @@ export function normalizeToolboxSpaces(toolbox, modules) {
|
|||
return { spaces, defaultSpaceId: defaultId, activeSpaceId };
|
||||
}
|
||||
|
||||
/**
|
||||
* Toolbox complète et valide à partir d'une valeur stockée ou importée (outils, espaces, icône, valeurs par défaut) ; `null` si ce n'est
|
||||
* pas un objet.
|
||||
*/
|
||||
export function normalizeToolbox(toolbox) {
|
||||
if (!toolbox || typeof toolbox !== "object") return null;
|
||||
const modules = (Array.isArray(toolbox.modules) ? toolbox.modules : []).map(normalizeToolboxModule).filter(Boolean);
|
||||
|
|
@ -226,6 +241,7 @@ export function normalizeToolbox(toolbox) {
|
|||
return normalized;
|
||||
}
|
||||
|
||||
/** Toolbox normalisée sans les valeurs par défaut, telle qu'elle est écrite en base et dans les exports. */
|
||||
export function compactToolboxForStorage(toolbox) {
|
||||
const normalized = normalizeToolbox(toolbox);
|
||||
if (!normalized) return null;
|
||||
|
|
@ -245,28 +261,37 @@ export function compactToolboxForStorage(toolbox) {
|
|||
return compact;
|
||||
}
|
||||
|
||||
/** `compactToolboxForStorage` appliqué à une liste ; les entrées invalides sont retirées. */
|
||||
export function compactToolboxesForStorage(toolboxes) {
|
||||
return (Array.isArray(toolboxes) ? toolboxes : []).map(compactToolboxForStorage).filter(Boolean);
|
||||
}
|
||||
|
||||
/** Clé IndexedDB des données d'un outil : `<toolbox>:<outil>`. */
|
||||
export function moduleStorageKey(toolboxId, moduleId) {
|
||||
return `${toolboxId}:${moduleId}`;
|
||||
}
|
||||
|
||||
/** Clé des données d'un outil dans un export global. Même forme que `moduleStorageKey`, mais c'est un format d'échange distinct. */
|
||||
export function globalModuleKey(toolboxId, moduleId) {
|
||||
return `${toolboxId}:${moduleId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Données d'un outil passées par le compacteur de son type ; un type sans compacteur est écrit tel quel (le test des compacteurs
|
||||
* l'interdit).
|
||||
*/
|
||||
export function compactModuleDataForStorage(type, value) {
|
||||
const compactor = MODULE_DATA_COMPACTORS[type];
|
||||
return compactor ? compactor(value) : value;
|
||||
}
|
||||
|
||||
/** Données des Mémos avec le planificateur lié remplacé par son nouvel id (copie ou import) ; lien vide s'il n'a pas suivi. */
|
||||
export function remapMemosPlannerLink(data, resolveModuleId) {
|
||||
if (!data || typeof data !== "object" || !data.plannerLink || data.plannerLink === "all") return data;
|
||||
return { ...data, plannerLink: resolveModuleId(data.plannerLink) || "" };
|
||||
}
|
||||
|
||||
/** Données d'un outil compactées selon son type, retrouvé dans la toolbox si `moduleType` n'est pas donné. */
|
||||
export function prepareModuleDataForStorage(toolboxes, toolboxId, moduleId, value, moduleType = "") {
|
||||
const module = toolboxes.find((toolbox) => toolbox.id === toolboxId)?.modules.find((item) => item.id === moduleId);
|
||||
return compactModuleDataForStorage(moduleType || module?.type, value);
|
||||
|
|
@ -493,10 +518,15 @@ function remapModuleDataForExport(type, data, nextId, moduleIdMap) {
|
|||
return compact;
|
||||
}
|
||||
|
||||
/** Copie des données d'un outil avec de nouveaux ids internes (entrées, sections, liens…), pour dupliquer un outil ou une toolbox. */
|
||||
export function copyModuleDataWithFreshIds(type, data, moduleIdMap = new Map()) {
|
||||
return remapModuleDataForExport(type, data, uid, moduleIdMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fichier d'export d'une toolbox (format version 2) : toolbox compactée et données de ses outils, avec de nouveaux ids
|
||||
* pour qu'un import ne heurte jamais l'original.
|
||||
*/
|
||||
export function createToolboxExportPayload(toolbox, moduleData) {
|
||||
const source = normalizeToolbox(toolbox);
|
||||
const nextId = createExportIdFactory();
|
||||
|
|
@ -535,6 +565,7 @@ export function pruneGameLinks(links, toolboxes) {
|
|||
.filter(([, toolboxId]) => typeof toolboxId === "string" && toolboxIds.has(toolboxId)));
|
||||
}
|
||||
|
||||
/** Fichier d'export de tout le stockage (format version 2) : toolboxes, données des outils et associations encore valides. */
|
||||
export function createGlobalExportPayload(toolboxes, links, moduleData) {
|
||||
const modules = {};
|
||||
toolboxes.forEach((toolbox) => {
|
||||
|
|
|
|||
|
|
@ -204,10 +204,12 @@ export const LIBRARY_CATEGORY_DEFINITIONS = [
|
|||
{ key: "buildsCommands", types: ["combos", "equipmentPlanner"] }
|
||||
];
|
||||
|
||||
/** Définition d'un type d'outil (titre, catégorie, chargeur…). Un type inconnu retombe sur le Bloc-notes au lieu de casser la page. */
|
||||
export function getToolboxModuleDefinition(type) {
|
||||
return TOOLBOX_MODULE_DEFINITIONS[type] || TOOLBOX_MODULE_DEFINITIONS.notepad;
|
||||
}
|
||||
|
||||
/** Titre donné à un nouvel outil de ce type. */
|
||||
export function getDefaultModuleTitle(type) {
|
||||
return getToolboxModuleDefinition(type).defaultTitle || "Outil";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,18 +11,22 @@ import { MAX_TOOLBOX_SPACES, normalizeModuleOrder, uid } from "./storage/toolbox
|
|||
|
||||
export const SPACE_GROUP_SEPARATOR = "::";
|
||||
|
||||
/** Espace affiché de la toolbox, ou le premier si l'espace actif n'existe plus. */
|
||||
export function getActiveToolboxSpace(toolbox) {
|
||||
return toolbox.spaces.find((space) => space.id === toolbox.activeSpaceId) || toolbox.spaces[0];
|
||||
}
|
||||
|
||||
/** Espace qui contient l'outil, ou le premier espace. */
|
||||
export function getModuleSpace(toolbox, moduleId) {
|
||||
return toolbox.spaces.find((space) => space.moduleOrder.one.includes(moduleId)) || toolbox.spaces[0];
|
||||
}
|
||||
|
||||
/** Identifiant de groupe pour le glisser-déposer : un espace et une colonne (`one`, `left`, `right`…) en une chaîne. */
|
||||
export function encodeSpaceColumn(spaceId, column = "one") {
|
||||
return `${spaceId}${SPACE_GROUP_SEPARATOR}${column}`;
|
||||
}
|
||||
|
||||
/** Inverse de `encodeSpaceColumn` : `{ spaceId, column }`. */
|
||||
export function decodeSpaceColumn(value) {
|
||||
const [spaceId = "", column = "one"] = String(value || "").split(SPACE_GROUP_SEPARATOR);
|
||||
return { spaceId, column };
|
||||
|
|
@ -43,6 +47,7 @@ function insertAround(ids, moduleId, targetId, placement) {
|
|||
return next;
|
||||
}
|
||||
|
||||
/** Toolbox avec l'outil ajouté, à la fin de l'espace demandé (ou de l'espace par défaut) et dans sa colonne la plus courte. */
|
||||
export function addModuleToToolboxSpace(toolbox, module, spaceId = toolbox.activeSpaceId) {
|
||||
const modules = [...toolbox.modules, module];
|
||||
const targetId = toolbox.spaces.some((space) => space.id === spaceId) ? spaceId : toolbox.defaultSpaceId;
|
||||
|
|
@ -60,6 +65,7 @@ export function addModuleToToolboxSpace(toolbox, module, spaceId = toolbox.activ
|
|||
};
|
||||
}
|
||||
|
||||
/** Toolbox sans l'outil, retiré de la liste et de l'ordre de chaque espace. Ses données stockées sont à supprimer à part. */
|
||||
export function removeModuleFromToolboxSpaces(toolbox, moduleId) {
|
||||
return {
|
||||
...toolbox,
|
||||
|
|
@ -68,6 +74,7 @@ export function removeModuleFromToolboxSpaces(toolbox, moduleId) {
|
|||
};
|
||||
}
|
||||
|
||||
/** Toolbox avec un nouvel espace vide, rendu actif ; inchangée si le nom est vide ou si le maximum d'espaces est atteint. */
|
||||
export function createToolboxSpace(toolbox, name) {
|
||||
if (toolbox.spaces.length >= MAX_TOOLBOX_SPACES || !String(name || "").trim()) return toolbox;
|
||||
const id = uid("space");
|
||||
|
|
@ -78,6 +85,7 @@ export function createToolboxSpace(toolbox, name) {
|
|||
};
|
||||
}
|
||||
|
||||
/** Toolbox sans l'espace donné ; ses outils rejoignent l'espace par défaut, qui ne peut pas être supprimé. */
|
||||
export function deleteToolboxSpace(toolbox, spaceId) {
|
||||
if (spaceId === toolbox.defaultSpaceId) return toolbox;
|
||||
const removed = toolbox.spaces.find((space) => space.id === spaceId);
|
||||
|
|
@ -99,6 +107,7 @@ export function deleteToolboxSpace(toolbox, spaceId) {
|
|||
};
|
||||
}
|
||||
|
||||
/** Toolbox avec l'espace `sourceId` déplacé avant ou après `targetId` ; l'espace par défaut reste toujours le premier. */
|
||||
export function reorderToolboxSpaces(toolbox, sourceId, targetId, placement = "before") {
|
||||
if (sourceId === toolbox.defaultSpaceId || sourceId === targetId) return toolbox;
|
||||
const secondary = toolbox.spaces.filter((space) => space.id !== toolbox.defaultSpaceId && space.id !== sourceId);
|
||||
|
|
@ -113,6 +122,10 @@ export function reorderToolboxSpaces(toolbox, sourceId, targetId, placement = "b
|
|||
return { ...toolbox, spaces: [fallback, ...secondary] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Toolbox avec l'outil déplacé avant ou après `targetModuleId`, dans le même espace ou dans un autre, et dans la colonne voulue
|
||||
* en affichage à deux colonnes.
|
||||
*/
|
||||
export function moveToolboxModule(toolbox, moduleId, {
|
||||
targetSpaceId,
|
||||
targetModuleId = "",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue