Snap canvas boxes to each other's edges and centres, with guides
Dragging a box snaps its edges and centre to other boxes' and to the canvas's sides, centre and top within 6 screen px, and draws a guide along each shared line; a resize snaps the dragged edge. The 5px grid still applies elsewhere. An "Align" button in the edit bar turns it off (kept per browser), and Ctrl/Cmd mid-drag skips it once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
* The box editor panel's size and its code's text size, shared between
|
||||
* BoxEditor (which draws the panel and its controls) and BoxCanvas (which
|
||||
* pads itself by the panel's width so the canvas rescales beside it rather
|
||||
* than under it). They are one admin's preference for their own screen, so
|
||||
* than under it), and whether dragged boxes snap to each other (BoxCanvas's
|
||||
* Align button). They are one admin's preference for their own screen, so
|
||||
* they live in localStorage, not the database.
|
||||
*/
|
||||
import { ref, watch } from "vue";
|
||||
@@ -28,6 +29,7 @@ const valid = (n) => typeof n === "number" && Number.isFinite(n);
|
||||
// so a width chosen on a wide monitor survives a visit from a narrow one.
|
||||
export const panelWidth = ref(valid(saved.width) ? Math.max(PANEL_WIDTH.min, saved.width) : PANEL_WIDTH.default);
|
||||
export const fontSize = ref(valid(saved.fontSize) ? clamp(saved.fontSize, FONT_SIZE.min, FONT_SIZE.max) : FONT_SIZE.default);
|
||||
export const snapping = ref(saved.snapping !== false);
|
||||
|
||||
export function setPanelWidth(width) {
|
||||
panelWidth.value = Math.round(clamp(width, PANEL_WIDTH.min, window.innerWidth));
|
||||
@@ -38,9 +40,9 @@ export function zoom(delta) {
|
||||
fontSize.value = delta === 0 ? FONT_SIZE.default : clamp(fontSize.value + delta, FONT_SIZE.min, FONT_SIZE.max);
|
||||
}
|
||||
|
||||
watch([panelWidth, fontSize], ([width, size]) => {
|
||||
watch([panelWidth, fontSize, snapping], ([width, size, snap]) => {
|
||||
try {
|
||||
localStorage.setItem(KEY, JSON.stringify({ width, fontSize: size }));
|
||||
localStorage.setItem(KEY, JSON.stringify({ width, fontSize: size, snapping: snap }));
|
||||
} catch {
|
||||
/* storage unavailable: the preference just won't outlive the tab */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user