mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-17 22:21:26 +01:00
Put a column drag back when the columns change, and keep a merged reason to Type
A drag keeps the columns' edges from when it began, so columns shown or hidden meanwhile, as App is when the first flow with an app arrives, would drop it against columns that are gone; it is put back instead. A failed flow's reason spans Type and Size, so while they part it keeps to Type's width rather than sliding over the column past Size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
80b587f507
commit
5e37fca58a
2 files changed
+35
-7
No files matched your search
@@ -633,8 +633,8 @@ function useColumnDragView(
|
||||
const ghost = snapshotColumn(event.id, event.x, root, header, list);
|
||||
const style = document.createElement("style");
|
||||
document.head.append(style);
|
||||
const width = cells[from]?.getBoundingClientRect().width ?? 0;
|
||||
drag.current = { ghost, ids, from, width, to: null, style };
|
||||
const widths = cells.map((c) => c.getBoundingClientRect().width);
|
||||
drag.current = { ghost, ids, widths, from, to: null, style };
|
||||
style.textContent = columnDragCss(drag.current);
|
||||
}
|
||||
}
|
||||
@@ -656,16 +656,16 @@ function useColumnDragView(
|
||||
|
||||
interface ColumnDragView {
|
||||
ghost: ColumnGhost | null;
|
||||
/** The columns shown, the dragged one's place among them and its width, and its target */
|
||||
/** The columns shown and their widths, the dragged one's place among them, and its target */
|
||||
ids: ColumnId[];
|
||||
widths: number[];
|
||||
from: number;
|
||||
width: number;
|
||||
to: number | null;
|
||||
style: HTMLStyleElement;
|
||||
}
|
||||
|
||||
/** The rules for a drag: the column hidden, and those it passes slid aside */
|
||||
function columnDragCss({ ids, from, width, to }: ColumnDragView): string {
|
||||
function columnDragCss({ ids, widths, from, to }: ColumnDragView): string {
|
||||
// A row's cell is the box in its grid: the column's child, or inside the `contents` span a
|
||||
// tooltip wraps it in, as a box that is only its contents can't move
|
||||
const cells = (is: string) =>
|
||||
@@ -679,10 +679,23 @@ function columnDragCss({ ids, from, width, to }: ColumnDragView): string {
|
||||
];
|
||||
const dragged = ids[from];
|
||||
if (dragged != null) rules.push(`${column(dragged)} { visibility: hidden; }`);
|
||||
columnShifts(ids.length, from, width, to).forEach((dx, i) => {
|
||||
const shifts = columnShifts(ids.length, from, widths[from] ?? 0, to);
|
||||
shifts.forEach((dx, i) => {
|
||||
const id = ids[i];
|
||||
if (dx !== 0 && id != null) rules.push(`${column(id)} { transform: translateX(${dx}px); }`);
|
||||
});
|
||||
// A failed flow's reason spans Type and Size together; while they part, it keeps to Type's
|
||||
// width, so it doesn't slide over the column past Size.
|
||||
const type = ids.indexOf("type");
|
||||
if (type !== -1 && ids[type + 1] === "size") {
|
||||
const size = type + 1;
|
||||
if (from === size || shifts[type] !== shifts[size]) {
|
||||
const is = '[data-flow-rows] [data-column="type"]';
|
||||
rules.push(
|
||||
`${is} > .col-span-2, ${is} > .contents > .col-span-2 { width: ${widths[type] ?? 0}px; }`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return rules.join("\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -382,6 +382,8 @@ function useColumnDrag({
|
||||
from: number;
|
||||
/** The labels' edges when the drag began, from the header's left, as the columns slide */
|
||||
cells: { left: number; right: number }[];
|
||||
/** The columns shown when it began, which the edges and `from` describe */
|
||||
shown: string;
|
||||
/** The pointer, across the window */
|
||||
x: number;
|
||||
/** The boundary it would move to, null where it would stay */
|
||||
@@ -418,7 +420,8 @@ function useColumnDrag({
|
||||
);
|
||||
const id = e.active.id as ColumnId;
|
||||
const x = pointer.current;
|
||||
state.current = { id, from, cells, x, to: null, ghostX: x, frame: 0 };
|
||||
const shown = shownKey(latest.current.columns);
|
||||
state.current = { id, from, cells, shown, x, to: null, ghostX: x, frame: 0 };
|
||||
latest.current.onColumnDrag({ type: "start", id, x });
|
||||
target(state.current);
|
||||
|
||||
@@ -460,6 +463,13 @@ function useColumnDrag({
|
||||
stop(false);
|
||||
}, [stop]);
|
||||
|
||||
// Columns shown or hidden under a drag, as App is when the first flow with an app arrives,
|
||||
// leave its edges and target describing columns that are gone; it is put back instead.
|
||||
const shown = shownKey(columns);
|
||||
useEffect(() => {
|
||||
if (state.current != null && state.current.shown !== shown) cancel();
|
||||
}, [shown, cancel]);
|
||||
|
||||
// The pointer from a press on the header until its release, read before dnd-kit sees it.
|
||||
// dnd-kit starts a drag on the move that crosses `DRAG_DISTANCE` and reports moves and the
|
||||
// release only once it has rendered the drag, so a release right after a move would drop
|
||||
@@ -522,3 +532,8 @@ function useColumnDrag({
|
||||
dndHandlers: { onDragStart, onDragEnd: drop, onDragCancel: cancel },
|
||||
};
|
||||
}
|
||||
|
||||
/** Which columns show, in order, to tell when that changes */
|
||||
function shownKey(columns: Column[]): string {
|
||||
return columns.map((c) => c.id).join(" ");
|
||||
}
|
||||
Reference in new issue
Block a user