diff --git a/src/LGraph.ts b/src/LGraph.ts index e14fd41..75e4028 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -47,19 +47,6 @@ type ParamsArray, K extends MethodNames> = export interface LGraphConfig { /** @deprecated Legacy config - unused */ align_to_grid?: any - /** - * When set to a positive number, when nodes are moved their positions will - * be rounded to the nearest multiple of this value. Half up. - * Default: `undefined` - * @todo Not implemented - see {@link LiteGraph.CANVAS_GRID_SIZE} - */ - snapToGrid?: number - /** - * If `true`, items always snap to the grid - modifier keys are ignored. - * When {@link snapToGrid} is falsy, a value of `1` is used. - * Default: `false` - */ - alwaysSnapToGrid?: boolean links_ontop?: any } @@ -791,7 +778,7 @@ export class LGraph implements LinkNetwork, Serialisable { const { state } = this // Ensure created items are snapped - if (this.config.alwaysSnapToGrid) { + if (LiteGraph.alwaysSnapToGrid) { const snapTo = this.getSnapToGridSize() if (snapTo) node.snapToGrid(snapTo) } @@ -1060,7 +1047,7 @@ export class LGraph implements LinkNetwork, Serialisable { * * Item positions are reounded to the nearest multiple of {@link LiteGraph.CANVAS_GRID_SIZE}. * - * When {@link config}.{@link LGraphConfig.alwaysSnapToGrid alwaysSnapToGrid} is enabled + * When {@link LiteGraph.alwaysSnapToGrid} is enabled * and the grid size is falsy, a default of 1 is used. * @param items The items to be snapped to the grid * @todo Currently only snaps nodes. @@ -1080,7 +1067,7 @@ export class LGraph implements LinkNetwork, Serialisable { */ getSnapToGridSize(): number { // Default to 1 when always snapping - return this.config.alwaysSnapToGrid + return LiteGraph.alwaysSnapToGrid ? LiteGraph.CANVAS_GRID_SIZE || 1 : LiteGraph.CANVAS_GRID_SIZE } diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 22d8193..431a031 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -3019,7 +3019,7 @@ export class LGraphCanvas { */ #processDraggedItems(e: CanvasPointerEvent): void { const { graph } = this - if (e.shiftKey || graph.config.alwaysSnapToGrid) + if (e.shiftKey || LiteGraph.alwaysSnapToGrid) graph.snapToGrid(this.selectedItems) this.dirty_canvas = true @@ -4180,7 +4180,7 @@ export class LGraphCanvas { } // TODO: Set snapping value when changed instead of once per frame - this.#snapToGrid = this.#shiftDown || this.graph.config.alwaysSnapToGrid + this.#snapToGrid = this.#shiftDown || LiteGraph.alwaysSnapToGrid ? this.graph.getSnapToGridSize() : undefined diff --git a/src/LiteGraphGlobal.ts b/src/LiteGraphGlobal.ts index f1651c3..e290897 100644 --- a/src/LiteGraphGlobal.ts +++ b/src/LiteGraphGlobal.ts @@ -166,6 +166,21 @@ export class LiteGraphGlobal { /** [true!] renders a partial border to highlight when a dragged link is snapped to a node */ snap_highlights_node = true + /** + * If `true`, items always snap to the grid - modifier keys are ignored. + * When {@link snapToGrid} is falsy, a value of `1` is used. + * Default: `false` + */ + alwaysSnapToGrid?: boolean + + /** + * When set to a positive number, when nodes are moved their positions will + * be rounded to the nearest multiple of this value. Half up. + * Default: `undefined` + * @todo Not implemented - see {@link LiteGraph.CANVAS_GRID_SIZE} + */ + snapToGrid?: number + /** [false on mobile] better true if not touch device, TODO add an helper/listener to close if false */ search_hide_on_mouse_leave = true /** diff --git a/test/__snapshots__/litegraph.test.ts.snap b/test/__snapshots__/litegraph.test.ts.snap index 3b39290..20c9c87 100644 --- a/test/__snapshots__/litegraph.test.ts.snap +++ b/test/__snapshots__/litegraph.test.ts.snap @@ -135,6 +135,7 @@ LiteGraphGlobal { "allow_multi_output_for_events": true, "allow_scripts": false, "alt_drag_do_clone_nodes": false, + "alwaysSnapToGrid": undefined, "auto_load_slot_types": false, "auto_sort_node_types": false, "catch_exceptions": true, @@ -170,6 +171,7 @@ LiteGraphGlobal { "slot_types_default_out": {}, "slot_types_in": [], "slot_types_out": [], + "snapToGrid": undefined, "snap_highlights_node": true, "snaps_for_comfy": true, "throw_errors": true,