feat(ui): let swapDimensions work on nodes without a preset widget

- Treat a missing preset widget like preset value 'custom' in swapDimensions
- Keep every preset access behind the custom check
- Add a test that swaps width and height directly on a preset-less node
This commit is contained in:
Vito Sansevero
2026-10-27 10:14:24 -07:00
parent 83ed5ae42d
commit 408fc5e2f8
2 changed files with 13 additions and 2 deletions
+11
View File
@@ -58,3 +58,14 @@ test('a throwing or recursive preset callback does not leave swapping locked', (
swapDimensions(node, app);
assert.deepEqual(node.widgets.map(widget => widget.value), ['640×960', 640, 960]);
});
test('nodes without a preset widget swap width and height directly', () => {
const calls = [];
const node = { widgets: [
{ name: 'width', value: 1344, callback(value) { calls.push(['width', value]); } },
{ name: 'height', value: 768, callback(value) { calls.push(['height', value]); } },
], graph: { setDirtyCanvas() { calls.push(['dirty']); } } };
swapDimensions(node, app);
assert.deepEqual(node.widgets.map(widget => widget.value), [768, 1344]);
assert.deepEqual(calls, [['width', 768], ['height', 1344], ['dirty']]);
});
+2 -2
View File
@@ -38,8 +38,8 @@ export function bindDimensionPresets(node, app) {
export function swapDimensions(node, app) {
const [preset, width, height] = widgets(node);
if (!preset || !width || !height || swapping.has(node)) return;
const custom = preset.value === 'custom';
if (!width || !height || swapping.has(node)) return;
const custom = !preset || preset.value === 'custom';
const dimensions = custom ? [width.value, height.value] : dimensionsFromPreset(preset.value);
if (!dimensions) return;
const [w, h] = dimensions;