mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Keep each dashboard group at one card width with no card left alone on a row
AI Assisted
This commit is contained in:
1 parent
c6265795ea
commit
3fe1de51ed
10 files changed
+181
-3
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/* card-rows.js: How many cards a dashboard group draws per row, so no card sits
|
||||
alone on a row. Pure: the dashboard measures, this decides. */
|
||||
|
||||
// The card sizes the grid used before: as many 240px cards as fit, 12px apart.
|
||||
// One more column is allowed while the cards stay at least 200px wide.
|
||||
const CARD = 240;
|
||||
const TIGHT = 200;
|
||||
const GAP = 12;
|
||||
|
||||
// The empty spots the last row leaves at `cols` across.
|
||||
const gapsAt = (count, cols) => (cols - (count % cols)) % cols;
|
||||
|
||||
// How bad a column count is: 0 is fine. One empty corner is fine from three
|
||||
// across; at two across it is a lone card, so it counts.
|
||||
function badness(count, cols) {
|
||||
const gaps = gapsAt(count, cols);
|
||||
if (gaps === 0 || (gaps === 1 && cols >= 3)) return 0;
|
||||
return gaps;
|
||||
}
|
||||
|
||||
// `{ cols, center }` for `count` cards in a grid `width` px wide. Every card
|
||||
// keeps one width. The count is what fits, one more (while cards stay 200px
|
||||
// wide) or one fewer (never below two), whichever leaves the fewest gaps; a
|
||||
// tie keeps what fits, then takes one more. A last row still short is
|
||||
// centered, but a group that fits in one row is drawn as it is.
|
||||
export function steadyColumns(count, width) {
|
||||
const fit = Math.max(1, Math.floor((Number(width) + GAP) / (CARD + GAP)) || 1);
|
||||
if (count <= fit) return { cols: fit, center: false };
|
||||
const candidates = [fit];
|
||||
if ((width + GAP) / (fit + 1) - GAP >= TIGHT) candidates.push(fit + 1);
|
||||
if (fit - 1 >= 2) candidates.push(fit - 1);
|
||||
let cols = fit;
|
||||
for (const c of candidates) if (badness(count, c) < badness(count, cols)) cols = c;
|
||||
return { cols, center: badness(count, cols) > 0 };
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { el, approvalTip, mdInto, releasesLink, copyButton, lightDismiss, SVG_NS
|
||||
import { needsRoleNudge, ROLE_NOT_SET } from "../starters.js";
|
||||
import { looks, saveLooks } from "../looks.js";
|
||||
import { RED_BANNER, RED_BANNER_IN_APP } from "../meter.js";
|
||||
import { steadyColumns } from "../card-rows.js";
|
||||
import {
|
||||
dashNoteKind,
|
||||
defaultSpec,
|
||||
@@ -285,10 +286,33 @@ export function renderDashboard(main) {
|
||||
if (note) revealNote(note, page.wake.typed);
|
||||
}
|
||||
main.appendChild(wrap);
|
||||
fitCardRows(wrap);
|
||||
watchCardRows(wrap);
|
||||
// Deferred: this runs inside render(), and the dialog is not part of it.
|
||||
queueMicrotask(hooks.maybeWelcome);
|
||||
}
|
||||
|
||||
// Each group's cards share one width, in as many columns as leave no card
|
||||
// alone on a row (card-rows.js). Measured from the grid's own width, so the
|
||||
// Card width setting and the window both count; only a change is written.
|
||||
function fitCardRows(root) {
|
||||
for (const grid of root.querySelectorAll(".dash-grid")) {
|
||||
const { cols, center } = steadyColumns(grid.children.length, grid.clientWidth);
|
||||
if (grid.style.getPropertyValue("--dash-cols") !== String(cols)) grid.style.setProperty("--dash-cols", String(cols));
|
||||
grid.classList.toggle("is-centered", center);
|
||||
}
|
||||
}
|
||||
|
||||
// One watcher, on the menu drawn last: a resize refits its groups. Fitting
|
||||
// changes only the menu's height, which refits to the same columns, so the
|
||||
// watcher never feeds itself.
|
||||
const rowsObserver = typeof ResizeObserver === "function" ? new ResizeObserver((entries) => entries.forEach((e) => fitCardRows(e.target))) : null;
|
||||
function watchCardRows(wrap) {
|
||||
if (!rowsObserver) return;
|
||||
rowsObserver.disconnect();
|
||||
rowsObserver.observe(wrap);
|
||||
}
|
||||
|
||||
const WAKE_TYPE_DELAY_MS = 350;
|
||||
|
||||
const WAKE_TYPE_EVERY_MS = 14;
|
||||
|
||||
@@ -173,7 +173,17 @@
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
|
||||
/* Every card in a group has one width, `--dash-cols` to a row: the dashboard
|
||||
picks the count (card-rows.js) so no card sits alone on a row, and centers a
|
||||
last row still short. The 3 is only the first paint's guess. */
|
||||
.dash-grid {
|
||||
--dash-cols: 3;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
.dash-grid > .dash-card { flex: 0 0 calc((100% - (var(--dash-cols) - 1) * 12px) / var(--dash-cols)); min-width: 0; }
|
||||
.dash-grid.is-centered { justify-content: center; }
|
||||
|
||||
/* A card IS a button, so it carries the reset the page's other big clickable
|
||||
surfaces do; the look is the panel look with a lift on hover, and the
|
||||
|
||||
@@ -440,7 +440,9 @@ h1 {
|
||||
|
||||
.attach-row { display: flex; align-items: center; margin: -4px 0 6px -13px; }
|
||||
.attach-row.is-under { margin: 6px 0 4px -13px; }
|
||||
.attach-row .suggest-chip { margin: 0 0 0 auto; }
|
||||
/* .btn on the chip's rule: pieces.css loads later, and .btn.tiny's bottom
|
||||
margin would otherwise lift the chip off the row's center line. */
|
||||
.attach-row .btn.suggest-chip { margin: 0 0 0 auto; }
|
||||
.attach-row .suggest-nudge { margin-left: auto; }
|
||||
.attach-row .suggest-nudge + .suggest-chip { margin-left: 9px; }
|
||||
.msg .suggest-tag {
|
||||
|
||||
Reference in new issue
Block a user