separation du css et du html
This commit is contained in:
+2
-16
@@ -2,24 +2,10 @@ services:
|
||||
epices:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- reverse-proxy_default
|
||||
ports:
|
||||
- "3000:3000" # à retirer si tu passes par Traefik (labels à la place)
|
||||
volumes:
|
||||
- epices-data:/data
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
|
||||
- "traefik.http.routers.saucissons-dev-epices-1.rule=Host(`dev.tuttifruitti.ddns.net`)"
|
||||
- "traefik.http.routers.saucissons-dev-epices-1.entrypoints=websecure"
|
||||
- "traefik.http.routers.saucissons-dev-epices-1.tls=true"
|
||||
- "traefik.http.routers.saucissons-dev-epices-1.tls.certresolver=letsencrypt"
|
||||
- "traefik.http.routers.saucissons-dev-epices-1.service=saucissons-dev-epices-1"
|
||||
|
||||
- "traefik.http.services.saucissons-dev-epices-1.loadbalancer.server.port=3000"
|
||||
|
||||
volumes:
|
||||
epices-data:
|
||||
|
||||
networks:
|
||||
reverse-proxy_default:
|
||||
external: true
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/* En-tête commun : titre + menu de navigation (utilisé par toutes les pages) */
|
||||
.topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
background: var(--accent, #8c2f2f);
|
||||
color: #fff;
|
||||
padding: calc(8px + env(safe-area-inset-top)) 16px 0;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.topbar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.topbar h1 {
|
||||
margin: 0;
|
||||
font-family: Georgia, "Times New Roman", serif;
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.menu { display: flex; gap: 4px; margin: 2px -6px 0; }
|
||||
|
||||
.menu a {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 42px;
|
||||
padding: 0 14px;
|
||||
color: rgba(255, 255, 255, 0.78);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
border-bottom: 3px solid transparent;
|
||||
}
|
||||
|
||||
.menu a:active { background: rgba(255, 255, 255, 0.12); }
|
||||
.menu a[aria-current="page"] { color: #fff; border-bottom-color: #fff; }
|
||||
|
||||
@media (min-width: 600px) {
|
||||
.menu a { flex: 0 0 auto; padding: 0 22px; }
|
||||
}
|
||||
|
||||
@media print {
|
||||
.topbar { display: none; }
|
||||
}
|
||||
@@ -0,0 +1,438 @@
|
||||
/* =====================================================================
|
||||
Calcul des épices : feuille de style unique pour toutes les pages
|
||||
|
||||
1. Variables et base
|
||||
2. En-tête et menu
|
||||
3. Composants communs (cartes, champs, boutons)
|
||||
4. Page « Calculateur » (index.html)
|
||||
5. Page « To-do » (todo.html)
|
||||
6. Grands écrans
|
||||
7. Impression
|
||||
===================================================================== */
|
||||
|
||||
|
||||
/* ---------- 1. Variables et base ---------- */
|
||||
:root {
|
||||
--bg: #f6f1ea;
|
||||
--card: #ffffff;
|
||||
--ink: #2b2420;
|
||||
--muted: #7a6e65;
|
||||
--line: #e6ddd2;
|
||||
--accent: #8c2f2f;
|
||||
--accent-dark: #742626;
|
||||
--accent-soft: #f7e8e5;
|
||||
--ok: #2f6b4f;
|
||||
--warn: #b35a00;
|
||||
--warn-soft: #fff1e0;
|
||||
--radius: 16px;
|
||||
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
line-height: 1.35;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
|
||||
|
||||
|
||||
/* ---------- 2. En-tête et menu (toutes les pages) ---------- */
|
||||
.topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
padding: calc(8px + env(safe-area-inset-top)) 16px 0;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.topbar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.topbar h1 {
|
||||
margin: 0;
|
||||
font-family: Georgia, "Times New Roman", serif;
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.menu { display: flex; gap: 4px; margin: 2px -6px 0; }
|
||||
|
||||
.menu a {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 42px;
|
||||
padding: 0 14px;
|
||||
color: rgba(255, 255, 255, 0.78);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
border-bottom: 3px solid transparent;
|
||||
}
|
||||
|
||||
.menu a:active { background: rgba(255, 255, 255, 0.12); }
|
||||
.menu a[aria-current="page"] { color: #fff; border-bottom-color: #fff; }
|
||||
|
||||
@media (min-width: 600px) {
|
||||
.menu a { flex: 0 0 auto; padding: 0 22px; }
|
||||
}
|
||||
|
||||
|
||||
/* ---------- 3. Composants communs ---------- */
|
||||
.card {
|
||||
background: var(--card);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 16px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 0.78rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
|
||||
|
||||
/* 16px minimum : évite le zoom automatique d'iOS au focus */
|
||||
input[type="text"], input[type="number"] {
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
font: inherit;
|
||||
font-size: 1.1rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
padding: 0 12px;
|
||||
border: 1.5px solid var(--line);
|
||||
border-radius: 12px;
|
||||
background: #fffdfa;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
|
||||
|
||||
.btn {
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
min-height: 52px;
|
||||
padding: 0 18px;
|
||||
border-radius: 14px;
|
||||
border: 1.5px solid var(--line);
|
||||
background: var(--card);
|
||||
color: var(--ink);
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:active { transform: scale(0.99); }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
.btn.primary:active { background: var(--accent-dark); }
|
||||
|
||||
|
||||
/* ---------- 4. Page « Calculateur » ---------- */
|
||||
|
||||
/* Récapitulatif dans la barre du haut */
|
||||
.summary { display: flex; gap: 16px; text-align: right; }
|
||||
.summary .lbl { display: block; font-size: 0.68rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
.summary b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* Rendement */
|
||||
.yield { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
.yield .field { grid-column: 1 / -1; }
|
||||
|
||||
.stat { background: #fbf7f1; border-radius: 12px; padding: 10px 12px; }
|
||||
.stat .label { font-size: 0.75rem; color: var(--muted); }
|
||||
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
|
||||
.stat.big .value { color: var(--accent); }
|
||||
|
||||
/* Réglages repliables */
|
||||
details.card { padding: 0; }
|
||||
details summary {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 52px;
|
||||
padding: 0 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
details summary::-webkit-details-marker { display: none; }
|
||||
details summary::after { content: "▾"; color: var(--muted); transition: transform 0.15s; }
|
||||
details[open] summary::after { transform: rotate(180deg); }
|
||||
details .settings { padding: 0 16px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
details .hint { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); }
|
||||
|
||||
/* Interrupteurs (couenne, filtre) */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-height: 44px;
|
||||
padding: 0 14px 0 10px;
|
||||
border: 1.5px solid var(--line);
|
||||
border-radius: 999px;
|
||||
background: #fff;
|
||||
font-weight: 600;
|
||||
font-size: 0.92rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
|
||||
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: #d9cfc3; position: relative; transition: background 0.15s; flex: none; }
|
||||
.switch .track::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 2px; left: 2px;
|
||||
width: 18px; height: 18px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
transition: transform 0.15s;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.switch:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
|
||||
.switch input:checked + .track { background: var(--accent); }
|
||||
.switch input:checked + .track::after { transform: translateX(16px); }
|
||||
.switch:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
|
||||
|
||||
.filterbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
|
||||
.count { font-size: 0.9rem; color: var(--muted); }
|
||||
.count b { color: var(--accent); }
|
||||
|
||||
/* Cartes bassines */
|
||||
.bassines { display: grid; gap: 12px; }
|
||||
|
||||
.bassine {
|
||||
background: var(--card);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
border: 2px solid transparent;
|
||||
padding: 14px;
|
||||
}
|
||||
.bassine.filled { border-color: var(--accent); background: #fffaf9; }
|
||||
.bassine.warn { border-color: var(--warn); background: var(--warn-soft); }
|
||||
|
||||
.b-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
|
||||
.b-name { font-weight: 700; font-size: 1.05rem; }
|
||||
.b-tare { font-size: 0.8rem; color: var(--muted); }
|
||||
|
||||
.b-input label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
|
||||
.input-wrap { position: relative; }
|
||||
.input-wrap input { height: 56px; font-size: 1.5rem; font-weight: 600; padding-right: 52px; }
|
||||
.clear {
|
||||
position: absolute;
|
||||
right: 6px; top: 6px;
|
||||
width: 44px; height: 44px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.clear:active { background: var(--line); }
|
||||
.input-wrap input:placeholder-shown + .clear { display: none; }
|
||||
|
||||
.b-results { margin-top: 12px; }
|
||||
.b-net { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
|
||||
.b-net .lbl { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
.b-net .val { font-size: 1.7rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
|
||||
.b-net .unit { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
|
||||
.warn .b-net .val { color: var(--warn); }
|
||||
|
||||
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
|
||||
.tile { grid-column: span 2; background: #fbf7f1; border-radius: 10px; padding: 8px 6px; text-align: center; }
|
||||
.tile:nth-child(n+4) { grid-column: span 3; }
|
||||
.tile .t-lbl { display: block; font-size: 0.7rem; color: var(--muted); }
|
||||
.tile .t-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1rem; }
|
||||
|
||||
.b-warn { margin: 10px 0 0; font-size: 0.85rem; color: var(--warn); font-weight: 600; }
|
||||
|
||||
/* Totaux */
|
||||
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.totals .stat:first-child { grid-column: 1 / -1; background: var(--accent-soft); }
|
||||
.totals .unit { font-size: 0.8rem; font-weight: 400; color: var(--muted); }
|
||||
|
||||
/* Boutons du bas de page */
|
||||
.actions { display: grid; gap: 10px; }
|
||||
|
||||
|
||||
/* ---------- 5. Page « To-do » ---------- */
|
||||
|
||||
/* Statut de connexion (barre du haut) */
|
||||
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; opacity: 0.95; }
|
||||
.live::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #7be0a8; }
|
||||
.live.off::before { background: #ffc266; }
|
||||
|
||||
/* Ajout d'une tâche */
|
||||
.add { display: flex; gap: 10px; margin-bottom: 14px; }
|
||||
.add input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 56px;
|
||||
padding: 0 14px;
|
||||
border-radius: 14px;
|
||||
background: var(--card);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.add input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
|
||||
.add .btn.primary { min-height: 56px; }
|
||||
|
||||
.info { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; font-size: 0.9rem; color: var(--muted); }
|
||||
.info b { color: var(--accent); }
|
||||
|
||||
/* Liste */
|
||||
.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: var(--card);
|
||||
border-radius: 14px;
|
||||
box-shadow: var(--shadow);
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
.item.flash { animation: flash 1.8s ease-out; }
|
||||
@keyframes flash {
|
||||
0% { background: #fde9c4; border-color: var(--warn); }
|
||||
100% { background: var(--card); border-color: transparent; }
|
||||
}
|
||||
|
||||
/* Poignée de réorganisation */
|
||||
.grip {
|
||||
flex: none;
|
||||
width: 46px;
|
||||
height: 56px;
|
||||
margin-left: 2px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
background: transparent;
|
||||
color: #b5a99b;
|
||||
cursor: grab;
|
||||
touch-action: none; /* le doigt déplace la tâche au lieu de faire défiler la page */
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
}
|
||||
.grip::before {
|
||||
content: "";
|
||||
display: block;
|
||||
width: 18px;
|
||||
height: 12px;
|
||||
margin: auto;
|
||||
background: repeating-linear-gradient(to bottom, currentColor 0 2px, transparent 2px 5px);
|
||||
}
|
||||
.grip:active, .grip:focus-visible { color: var(--accent); background: var(--accent-soft); outline: none; }
|
||||
|
||||
.item.dragging {
|
||||
position: relative;
|
||||
z-index: 5;
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 10px 28px rgba(43, 36, 32, 0.28);
|
||||
will-change: transform;
|
||||
}
|
||||
body.glisse { user-select: none; -webkit-user-select: none; cursor: grabbing; }
|
||||
|
||||
.check {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
min-height: 60px;
|
||||
padding: 8px 6px 8px 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
|
||||
.box {
|
||||
flex: none;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 9px;
|
||||
border: 2px solid #cfc3b5;
|
||||
background: #fffdfa;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
transition: background 0.12s, border-color 0.12s;
|
||||
}
|
||||
.box::after {
|
||||
content: "";
|
||||
width: 7px;
|
||||
height: 14px;
|
||||
border: solid #fff;
|
||||
border-width: 0 3px 3px 0;
|
||||
transform: translateY(-1px) rotate(45deg) scale(0);
|
||||
transition: transform 0.12s;
|
||||
}
|
||||
.check input:checked + .box { background: var(--ok); border-color: var(--ok); }
|
||||
.check input:checked + .box::after { transform: translateY(-1px) rotate(45deg) scale(1); }
|
||||
.check input:focus-visible + .box { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
|
||||
|
||||
.txt { font-size: 1.05rem; overflow-wrap: anywhere; }
|
||||
.item.done .txt { color: var(--muted); text-decoration: line-through; }
|
||||
|
||||
.del {
|
||||
flex: none;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
margin-right: 4px;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.del:active { background: var(--line); }
|
||||
|
||||
.vide { text-align: center; color: var(--muted); padding: 36px 12px; }
|
||||
|
||||
.erreur {
|
||||
margin: 0 0 12px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 12px;
|
||||
background: var(--warn-soft);
|
||||
color: var(--warn);
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.todo-actions { margin-top: 16px; display: grid; }
|
||||
|
||||
|
||||
/* ---------- 6. Grands écrans ---------- */
|
||||
@media (min-width: 900px) {
|
||||
.wrap-large { max-width: 1000px; } /* page Calculateur : deux colonnes de bassines */
|
||||
.bassines { grid-template-columns: 1fr 1fr; }
|
||||
.actions { grid-template-columns: 1fr 1fr; }
|
||||
}
|
||||
|
||||
|
||||
/* ---------- 7. Impression ---------- */
|
||||
@media print {
|
||||
body { background: #fff; }
|
||||
.topbar, .no-print, .clear { display: none !important; }
|
||||
.card, .bassine { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
|
||||
.bassine:not(.filled) { display: none; } /* on n'imprime que les bassines pesées */
|
||||
.bassines { grid-template-columns: 1fr 1fr; }
|
||||
input { border: none; background: none; }
|
||||
details { display: none; }
|
||||
}
|
||||
+2
-224
@@ -5,229 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#8c2f2f" />
|
||||
<title>Calculateur d'épices</title>
|
||||
<link rel="stylesheet" href="assets/menu.css" />
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f6f1ea;
|
||||
--card: #ffffff;
|
||||
--ink: #2b2420;
|
||||
--muted: #7a6e65;
|
||||
--line: #e6ddd2;
|
||||
--accent: #8c2f2f;
|
||||
--accent-dark: #742626;
|
||||
--accent-soft: #f7e8e5;
|
||||
--warn: #b35a00;
|
||||
--warn-soft: #fff1e0;
|
||||
--radius: 16px;
|
||||
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
line-height: 1.35;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
/* ---------- Récapitulatif dans la barre du haut (le reste : assets/menu.css) ---------- */
|
||||
.summary { display: flex; gap: 16px; text-align: right; }
|
||||
.summary .lbl { display: block; font-size: 0.68rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
.summary b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
|
||||
|
||||
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
|
||||
|
||||
/* ---------- Cartes génériques ---------- */
|
||||
.card {
|
||||
background: var(--card);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 16px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 0.78rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
|
||||
|
||||
/* 16px minimum : évite le zoom automatique d'iOS au focus */
|
||||
input[type="text"], input[type="number"] {
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
font: inherit;
|
||||
font-size: 1.1rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
padding: 0 12px;
|
||||
border: 1.5px solid var(--line);
|
||||
border-radius: 12px;
|
||||
background: #fffdfa;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
|
||||
|
||||
/* ---------- Rendement ---------- */
|
||||
.yield { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
.yield .field { grid-column: 1 / -1; }
|
||||
|
||||
.stat { background: #fbf7f1; border-radius: 12px; padding: 10px 12px; }
|
||||
.stat .label { font-size: 0.75rem; color: var(--muted); }
|
||||
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
|
||||
.stat.big .value { color: var(--accent); }
|
||||
|
||||
/* ---------- Réglages repliables ---------- */
|
||||
details.card { padding: 0; }
|
||||
details summary {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 52px;
|
||||
padding: 0 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
details summary::-webkit-details-marker { display: none; }
|
||||
details summary::after { content: "▾"; color: var(--muted); transition: transform 0.15s; }
|
||||
details[open] summary::after { transform: rotate(180deg); }
|
||||
details .settings { padding: 0 16px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
details .hint { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); }
|
||||
|
||||
/* ---------- Interrupteurs (couenne, filtre) ---------- */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-height: 44px;
|
||||
padding: 0 14px 0 10px;
|
||||
border: 1.5px solid var(--line);
|
||||
border-radius: 999px;
|
||||
background: #fff;
|
||||
font-weight: 600;
|
||||
font-size: 0.92rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
|
||||
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: #d9cfc3; position: relative; transition: background 0.15s; flex: none; }
|
||||
.switch .track::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 2px; left: 2px;
|
||||
width: 18px; height: 18px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
transition: transform 0.15s;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.switch:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
|
||||
.switch input:checked + .track { background: var(--accent); }
|
||||
.switch input:checked + .track::after { transform: translateX(16px); }
|
||||
.switch:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
|
||||
|
||||
.filterbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
|
||||
.count { font-size: 0.9rem; color: var(--muted); }
|
||||
.count b { color: var(--accent); }
|
||||
|
||||
/* ---------- Cartes bassines ---------- */
|
||||
.bassines { display: grid; gap: 12px; }
|
||||
|
||||
.bassine {
|
||||
background: var(--card);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
border: 2px solid transparent;
|
||||
padding: 14px;
|
||||
}
|
||||
.bassine.filled { border-color: var(--accent); background: #fffaf9; }
|
||||
.bassine.warn { border-color: var(--warn); background: var(--warn-soft); }
|
||||
|
||||
.b-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
|
||||
.b-name { font-weight: 700; font-size: 1.05rem; }
|
||||
.b-tare { font-size: 0.8rem; color: var(--muted); }
|
||||
|
||||
.b-input label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
|
||||
.input-wrap { position: relative; }
|
||||
.input-wrap input { height: 56px; font-size: 1.5rem; font-weight: 600; padding-right: 52px; }
|
||||
.clear {
|
||||
position: absolute;
|
||||
right: 6px; top: 6px;
|
||||
width: 44px; height: 44px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.clear:active { background: var(--line); }
|
||||
.input-wrap input:placeholder-shown + .clear { display: none; }
|
||||
|
||||
.b-results { margin-top: 12px; }
|
||||
.b-net { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
|
||||
.b-net .lbl { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
.b-net .val { font-size: 1.7rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
|
||||
.b-net .unit { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
|
||||
.warn .b-net .val { color: var(--warn); }
|
||||
|
||||
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
|
||||
.tile { grid-column: span 2; background: #fbf7f1; border-radius: 10px; padding: 8px 6px; text-align: center; }
|
||||
.tile:nth-child(n+4) { grid-column: span 3; }
|
||||
.tile .t-lbl { display: block; font-size: 0.7rem; color: var(--muted); }
|
||||
.tile .t-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1rem; }
|
||||
|
||||
.b-warn { margin: 10px 0 0; font-size: 0.85rem; color: var(--warn); font-weight: 600; }
|
||||
|
||||
/* ---------- Totaux ---------- */
|
||||
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.totals .stat:first-child { grid-column: 1 / -1; background: var(--accent-soft); }
|
||||
.totals .unit { font-size: 0.8rem; font-weight: 400; color: var(--muted); }
|
||||
|
||||
/* ---------- Actions ---------- */
|
||||
.actions { display: grid; gap: 10px; }
|
||||
.btn {
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
min-height: 52px;
|
||||
border-radius: 14px;
|
||||
border: 1.5px solid var(--line);
|
||||
background: var(--card);
|
||||
color: var(--ink);
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:active { transform: scale(0.99); }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
.btn.primary:active { background: var(--accent-dark); }
|
||||
|
||||
/* ---------- Grands écrans : deux colonnes ---------- */
|
||||
@media (min-width: 900px) {
|
||||
.wrap { max-width: 1000px; }
|
||||
.bassines { grid-template-columns: 1fr 1fr; }
|
||||
.actions { grid-template-columns: 1fr 1fr; }
|
||||
}
|
||||
|
||||
/* ---------- Impression : uniquement ce qui a été pesé ---------- */
|
||||
@media print {
|
||||
body { background: #fff; }
|
||||
.topbar, .no-print, .clear { display: none !important; }
|
||||
.card, .bassine { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
|
||||
.bassine:not(.filled) { display: none; }
|
||||
.bassines { grid-template-columns: 1fr 1fr; }
|
||||
input { border: none; background: none; }
|
||||
details { display: none; }
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
@@ -244,7 +22,7 @@
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="wrap">
|
||||
<main class="wrap wrap-large">
|
||||
<section class="card">
|
||||
<h2>Rendement</h2>
|
||||
<div class="yield">
|
||||
|
||||
+160
-157
@@ -5,161 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#8c2f2f" />
|
||||
<title>To-do – Calcul des épices</title>
|
||||
<link rel="stylesheet" href="assets/menu.css" />
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f6f1ea;
|
||||
--card: #ffffff;
|
||||
--ink: #2b2420;
|
||||
--muted: #7a6e65;
|
||||
--line: #e6ddd2;
|
||||
--accent: #8c2f2f;
|
||||
--accent-dark: #742626;
|
||||
--accent-soft: #f7e8e5;
|
||||
--ok: #2f6b4f;
|
||||
--warn: #b35a00;
|
||||
--radius: 16px;
|
||||
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
line-height: 1.35;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
|
||||
|
||||
/* Statut de connexion (barre du haut) */
|
||||
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; opacity: 0.95; }
|
||||
.live::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #7be0a8; }
|
||||
.live.off::before { background: #ffc266; }
|
||||
|
||||
/* Ajout */
|
||||
.add { display: flex; gap: 10px; margin-bottom: 14px; }
|
||||
.add input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 56px;
|
||||
padding: 0 14px;
|
||||
font: inherit;
|
||||
font-size: 1.1rem; /* 16px minimum : pas de zoom iOS */
|
||||
border: 1.5px solid var(--line);
|
||||
border-radius: 14px;
|
||||
background: var(--card);
|
||||
color: var(--ink);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.add input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
|
||||
|
||||
.btn {
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
min-height: 52px;
|
||||
padding: 0 18px;
|
||||
border-radius: 14px;
|
||||
border: 1.5px solid var(--line);
|
||||
background: var(--card);
|
||||
color: var(--ink);
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:active { transform: scale(0.98); }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-height: 56px; }
|
||||
.btn.primary:active { background: var(--accent-dark); }
|
||||
|
||||
.info { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; font-size: 0.9rem; color: var(--muted); }
|
||||
.info b { color: var(--accent); }
|
||||
|
||||
/* Liste */
|
||||
.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: var(--card);
|
||||
border-radius: 14px;
|
||||
box-shadow: var(--shadow);
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
.item.flash { animation: flash 1.8s ease-out; }
|
||||
@keyframes flash {
|
||||
0% { background: #fde9c4; border-color: var(--warn); }
|
||||
100% { background: var(--card); border-color: transparent; }
|
||||
}
|
||||
|
||||
.check {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
min-height: 60px;
|
||||
padding: 8px 6px 8px 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
|
||||
.box {
|
||||
flex: none;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 9px;
|
||||
border: 2px solid #cfc3b5;
|
||||
background: #fffdfa;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
transition: background 0.12s, border-color 0.12s;
|
||||
}
|
||||
.box::after {
|
||||
content: "";
|
||||
width: 7px;
|
||||
height: 14px;
|
||||
border: solid #fff;
|
||||
border-width: 0 3px 3px 0;
|
||||
transform: translateY(-1px) rotate(45deg) scale(0);
|
||||
transition: transform 0.12s;
|
||||
}
|
||||
.check input:checked + .box { background: var(--ok); border-color: var(--ok); }
|
||||
.check input:checked + .box::after { transform: translateY(-1px) rotate(45deg) scale(1); }
|
||||
.check input:focus-visible + .box { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
|
||||
|
||||
.txt { font-size: 1.05rem; overflow-wrap: anywhere; }
|
||||
.item.done .txt { color: var(--muted); text-decoration: line-through; }
|
||||
|
||||
.del {
|
||||
flex: none;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
margin-right: 4px;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.del:active { background: var(--line); }
|
||||
|
||||
.vide { text-align: center; color: var(--muted); padding: 36px 12px; }
|
||||
|
||||
.erreur {
|
||||
margin: 0 0 12px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 12px;
|
||||
background: #fff1e0;
|
||||
color: var(--warn);
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.actions { margin-top: 16px; display: grid; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
@@ -190,7 +36,7 @@
|
||||
<ul class="liste" id="liste"></ul>
|
||||
<p class="vide" id="vide" hidden>Aucune tâche pour l'instant.</p>
|
||||
|
||||
<div class="actions">
|
||||
<div class="todo-actions">
|
||||
<button type="button" class="btn" id="btnNettoyer" hidden>Supprimer les tâches cochées</button>
|
||||
</div>
|
||||
</main>
|
||||
@@ -201,10 +47,16 @@
|
||||
let todos = [];
|
||||
let premierChargement = true;
|
||||
let minuterieErreur;
|
||||
let glisse = null; // état du glissement en cours (null = aucun)
|
||||
let enAttente = null; // liste reçue pendant un glissement, appliquée ensuite
|
||||
|
||||
// ---------- Affichage ----------
|
||||
function rendre(modifies = new Set()) {
|
||||
const liste = $("liste");
|
||||
// On retient l'élément qui avait le focus pour le lui rendre après le redessin
|
||||
const actif = document.activeElement;
|
||||
const lignActive = actif && actif.closest ? actif.closest(".item") : null;
|
||||
const focus = lignActive ? { id: lignActive.dataset.id, poignee: actif.classList.contains("grip") } : null;
|
||||
liste.textContent = "";
|
||||
|
||||
for (const t of todos) {
|
||||
@@ -230,7 +82,13 @@
|
||||
suppr.setAttribute("aria-label", "Supprimer : " + t.text);
|
||||
suppr.textContent = "✕";
|
||||
|
||||
li.append(etiquette, suppr);
|
||||
const poignee = document.createElement("button");
|
||||
poignee.type = "button";
|
||||
poignee.className = "grip";
|
||||
poignee.title = "Glisser pour déplacer";
|
||||
poignee.setAttribute("aria-label", "Déplacer : " + t.text + " (glisser, ou flèches haut et bas)");
|
||||
|
||||
li.append(poignee, etiquette, suppr);
|
||||
liste.append(li);
|
||||
}
|
||||
|
||||
@@ -239,10 +97,21 @@
|
||||
$("faites").textContent = faites;
|
||||
$("vide").hidden = todos.length > 0;
|
||||
$("btnNettoyer").hidden = faites === 0;
|
||||
|
||||
if (focus) {
|
||||
const ligne = liste.querySelector(`.item[data-id="${CSS.escape(focus.id)}"]`);
|
||||
const cible = ligne && ligne.querySelector(focus.poignee ? ".grip" : 'input[type="checkbox"]');
|
||||
if (cible) cible.focus({ preventScroll: true });
|
||||
}
|
||||
}
|
||||
|
||||
// Reçoit la liste du serveur ; met en évidence ce que les autres viennent de changer
|
||||
function recevoir(nouvelle) {
|
||||
// Pendant un glissement, on ne redessine pas la liste (la carte déplacée disparaîtrait)
|
||||
if (glisse) {
|
||||
enAttente = nouvelle;
|
||||
return;
|
||||
}
|
||||
const avant = new Map(todos.map((t) => [t.id, t]));
|
||||
const modifies = new Set();
|
||||
if (!premierChargement) {
|
||||
@@ -342,6 +211,140 @@
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- Réorganisation : glisser la poignée (doigt ou souris) ou flèches haut/bas ----------
|
||||
// Le serveur ne reçoit qu'un déplacement : « cette tâche juste avant celle-là » (ou à la fin)
|
||||
async function validerOrdre(li) {
|
||||
// L'ordre local suit déjà l'ordre affiché à l'écran
|
||||
const parId = new Map(todos.map((t) => [t.id, t]));
|
||||
todos = [...$("liste").children].map((el) => parId.get(el.dataset.id)).filter(Boolean);
|
||||
const suivante = li.nextElementSibling;
|
||||
try {
|
||||
await appeler("POST", "/api/todos/" + li.dataset.id + "/move", {
|
||||
beforeId: suivante ? suivante.dataset.id : null,
|
||||
});
|
||||
} catch {
|
||||
afficherErreur("Déplacement impossible, réessaie.");
|
||||
await resynchroniser();
|
||||
}
|
||||
}
|
||||
|
||||
// Replace la carte sous le doigt et échange sa place avec ses voisines quand il le faut
|
||||
function majGlisser() {
|
||||
const { li } = glisse;
|
||||
const liste = $("liste");
|
||||
li.style.transform = `translateY(${glisse.y - glisse.departY}px)`;
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const r = li.getBoundingClientRect();
|
||||
const centre = r.top + r.height / 2;
|
||||
const suivante = li.nextElementSibling;
|
||||
const precedente = li.previousElementSibling;
|
||||
let voisine = null;
|
||||
let apres = false;
|
||||
if (suivante && centre > suivante.getBoundingClientRect().top + suivante.offsetHeight / 2) {
|
||||
voisine = suivante;
|
||||
apres = true;
|
||||
} else if (precedente && centre < precedente.getBoundingClientRect().top + precedente.offsetHeight / 2) {
|
||||
voisine = precedente;
|
||||
}
|
||||
if (!voisine) break;
|
||||
|
||||
const hautAvant = li.getBoundingClientRect().top;
|
||||
liste.insertBefore(li, apres ? voisine.nextSibling : voisine);
|
||||
// Sa place « de base » a changé : on corrige pour que la carte reste exactement sous le doigt
|
||||
glisse.departY += li.getBoundingClientRect().top - hautAvant;
|
||||
li.style.transform = `translateY(${glisse.y - glisse.departY}px)`;
|
||||
}
|
||||
}
|
||||
|
||||
// Fait défiler la page quand on approche du bord de l'écran pendant un glissement
|
||||
function defilementAuto() {
|
||||
if (!glisse) return;
|
||||
const haut = 150; // sous la barre du haut, qui reste collée
|
||||
const bas = window.innerHeight - 90;
|
||||
let vitesse = 0;
|
||||
if (glisse.y < haut) vitesse = -Math.ceil((haut - glisse.y) / 8);
|
||||
else if (glisse.y > bas) vitesse = Math.ceil((glisse.y - bas) / 8);
|
||||
vitesse = Math.max(-24, Math.min(24, vitesse));
|
||||
if (vitesse) {
|
||||
const avant = window.scrollY;
|
||||
window.scrollBy(0, vitesse);
|
||||
const reel = window.scrollY - avant;
|
||||
if (reel) {
|
||||
glisse.departY -= reel; // la page a bougé : la carte doit suivre le doigt
|
||||
majGlisser();
|
||||
}
|
||||
}
|
||||
requestAnimationFrame(defilementAuto);
|
||||
}
|
||||
|
||||
async function finGlisser() {
|
||||
if (!glisse) return;
|
||||
const { li, indexDepart } = glisse;
|
||||
li.classList.remove("dragging");
|
||||
li.style.transform = "";
|
||||
document.body.classList.remove("glisse");
|
||||
const aBouge = [...$("liste").children].indexOf(li) !== indexDepart;
|
||||
glisse = null;
|
||||
if (aBouge) await validerOrdre(li);
|
||||
if (enAttente) {
|
||||
enAttente = null;
|
||||
await resynchroniser(); // des changements d'autres personnes sont arrivés pendant le glissement
|
||||
}
|
||||
}
|
||||
|
||||
$("liste").addEventListener("pointerdown", (e) => {
|
||||
const poignee = e.target.closest(".grip");
|
||||
if (!poignee || glisse || (e.pointerType === "mouse" && e.button !== 0)) return;
|
||||
e.preventDefault();
|
||||
const li = poignee.closest(".item");
|
||||
poignee.setPointerCapture(e.pointerId);
|
||||
glisse = {
|
||||
li,
|
||||
pointerId: e.pointerId,
|
||||
departY: e.clientY,
|
||||
y: e.clientY,
|
||||
indexDepart: [...$("liste").children].indexOf(li),
|
||||
};
|
||||
li.classList.add("dragging");
|
||||
document.body.classList.add("glisse");
|
||||
requestAnimationFrame(defilementAuto);
|
||||
});
|
||||
|
||||
$("liste").addEventListener("pointermove", (e) => {
|
||||
if (!glisse || e.pointerId !== glisse.pointerId) return;
|
||||
glisse.y = e.clientY;
|
||||
majGlisser();
|
||||
});
|
||||
|
||||
const relacher = (e) => {
|
||||
if (glisse && e.pointerId === glisse.pointerId) finGlisser();
|
||||
};
|
||||
$("liste").addEventListener("pointerup", relacher);
|
||||
$("liste").addEventListener("pointercancel", relacher);
|
||||
$("liste").addEventListener("lostpointercapture", relacher);
|
||||
|
||||
// Pas de menu contextuel au toucher long sur la poignée
|
||||
$("liste").addEventListener("contextmenu", (e) => {
|
||||
if (e.target.closest(".grip")) e.preventDefault();
|
||||
});
|
||||
|
||||
// Clavier : la poignée prise au focus se déplace avec les flèches haut / bas
|
||||
$("liste").addEventListener("keydown", (e) => {
|
||||
if (!e.target.matches(".grip") || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
|
||||
e.preventDefault();
|
||||
const li = e.target.closest(".item");
|
||||
if (e.key === "ArrowUp" && li.previousElementSibling) {
|
||||
li.parentNode.insertBefore(li, li.previousElementSibling);
|
||||
} else if (e.key === "ArrowDown" && li.nextElementSibling) {
|
||||
li.parentNode.insertBefore(li.nextElementSibling, li);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
e.target.focus();
|
||||
validerOrdre(li);
|
||||
});
|
||||
|
||||
// ---------- Interactions ----------
|
||||
$("formAjout").addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -94,7 +94,7 @@ const nettoyerTexte = (valeur) => String(valeur ?? "").replace(/\s+/g, " ").trim
|
||||
|
||||
// ---------- API ----------
|
||||
async function api(req, res, url) {
|
||||
const [, ressource, id] = url.pathname.split("/").filter(Boolean); // /api/<ressource>/<id>
|
||||
const [, ressource, id, action] = url.pathname.split("/").filter(Boolean); // /api/<ressource>/<id>/<action>
|
||||
|
||||
if (ressource === "events" && req.method === "GET") {
|
||||
res.writeHead(200, {
|
||||
@@ -136,6 +136,23 @@ async function api(req, res, url) {
|
||||
return envoyerJson(res, 200, todos);
|
||||
}
|
||||
|
||||
// POST /api/todos/:id/move { beforeId } : place la tâche juste avant beforeId (ou à la fin si null)
|
||||
// Un déplacement = une seule tâche qui bouge : pas de conflit si quelqu'un d'autre modifie la liste en même temps
|
||||
if (id && action === "move" && req.method === "POST") {
|
||||
const corps = await lireJson(req);
|
||||
const index = todos.findIndex((t) => t.id === id);
|
||||
if (index === -1) return envoyerJson(res, 404, { erreur: "Tâche introuvable" });
|
||||
const [tache] = todos.splice(index, 1);
|
||||
const cible = typeof corps.beforeId === "string" ? todos.findIndex((t) => t.id === corps.beforeId) : -1;
|
||||
if (cible === -1) todos.push(tache);
|
||||
else todos.splice(cible, 0, tache);
|
||||
sauvegarder();
|
||||
diffuser();
|
||||
return envoyerJson(res, 200, todos);
|
||||
}
|
||||
|
||||
if (action) return envoyerJson(res, 404, { erreur: "Introuvable" });
|
||||
|
||||
// PATCH /api/todos/:id { done?, text? }
|
||||
if (id && req.method === "PATCH") {
|
||||
const tache = todos.find((t) => t.id === id);
|
||||
|
||||
Reference in New Issue
Block a user