jellyflow-runtime 0.2.0

Headless store, rules, schema, profile, and change pipeline for Jellyflow.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
use super::*;

#[test]
fn pane_click_distance_matches_xyflow_suppression_policy() {
    assert_eq!(
        resolve_pane_click_distance(PaneClickDistanceInput::new(7.0, false)),
        7.0
    );
    assert_eq!(
        resolve_pane_click_distance(PaneClickDistanceInput::new(-1.0, false)),
        0.0
    );
    assert_eq!(
        resolve_pane_click_distance(PaneClickDistanceInput::new(f32::NAN, false)),
        0.0
    );
    assert!(
        resolve_pane_click_distance(PaneClickDistanceInput::new(7.0, true)).is_infinite(),
        "selection-on-drag suppresses pane clicks"
    );
}

#[test]
fn viewport_scroll_policy_maps_pan_on_scroll_to_screen_delta() {
    let state = NodeGraphInteractionState {
        pan_on_scroll: true,
        pan_on_scroll_speed: 2.0,
        pan_on_scroll_mode: NodeGraphPanOnScrollMode::Horizontal,
        ..NodeGraphInteractionState::default()
    };

    let intent = resolve_viewport_scroll_gesture(
        &state.pan_interaction(),
        &state.zoom_interaction(),
        ViewportGestureContext::idle(),
        ViewportScrollInput::new(
            CanvasPoint { x: 12.0, y: -8.0 },
            CanvasPoint { x: 80.0, y: 20.0 },
            false,
            2.0,
            0.25,
            4.0,
        ),
    )
    .expect("pan-on-scroll intent");

    assert_eq!(intent.move_kind(), ViewportMoveKind::PanScroll);
    assert_eq!(
        intent,
        ViewportGestureIntent::Pan {
            kind: ViewportMoveKind::PanScroll,
            request: ViewportPanRequest::new(CanvasPoint { x: -24.0, y: 0.0 }),
        }
    );
}

#[test]
fn viewport_scroll_policy_prioritizes_zoom_activation_and_pinch() {
    let state = NodeGraphInteractionState {
        pan_on_scroll: true,
        zoom_on_scroll: false,
        zoom_on_pinch: true,
        ..NodeGraphInteractionState::default()
    };

    let zoom_by_activation = resolve_viewport_scroll_gesture(
        &state.pan_interaction(),
        &state.zoom_interaction(),
        ViewportGestureContext {
            zoom_activation_key_pressed: true,
            ..ViewportGestureContext::idle()
        },
        ViewportScrollInput::new(
            CanvasPoint { x: 0.0, y: 32.0 },
            CanvasPoint { x: 50.0, y: 25.0 },
            false,
            1.75,
            0.25,
            4.0,
        ),
    )
    .expect("activation-key zoom intent");
    assert_eq!(zoom_by_activation.move_kind(), ViewportMoveKind::ZoomWheel);

    let pinch = resolve_viewport_scroll_gesture(
        &state.pan_interaction(),
        &state.zoom_interaction(),
        ViewportGestureContext::idle(),
        ViewportScrollInput::new(
            CanvasPoint { x: 0.0, y: 32.0 },
            CanvasPoint { x: 50.0, y: 25.0 },
            true,
            2.0,
            0.25,
            4.0,
        ),
    )
    .expect("pinch zoom intent");
    assert_eq!(pinch.move_kind(), ViewportMoveKind::ZoomPinch);

    let pinch_disabled_state = NodeGraphInteractionState {
        zoom_on_pinch: false,
        ..state
    };
    let err = resolve_viewport_scroll_gesture(
        &pinch_disabled_state.pan_interaction(),
        &pinch_disabled_state.zoom_interaction(),
        ViewportGestureContext::idle(),
        ViewportScrollInput::new(
            CanvasPoint { x: 0.0, y: 32.0 },
            CanvasPoint { x: 50.0, y: 25.0 },
            true,
            2.0,
            0.25,
            4.0,
        ),
    )
    .expect_err("pinch should be rejected when disabled");
    assert_eq!(err, ViewportGestureRejection::PinchDisabled);
}

#[test]
fn viewport_drag_pan_policy_respects_buttons_and_context() {
    let state = NodeGraphInteractionState {
        pan_on_drag: NodeGraphPanOnDragButtons {
            left: false,
            middle: false,
            right: true,
        },
        ..NodeGraphInteractionState::default()
    };
    let pan = state.pan_interaction();

    let accepted = resolve_viewport_drag_pan_gesture(
        &pan,
        ViewportGestureContext::idle(),
        ViewportDragPanInput::new(
            ViewportPointerButton::Right,
            CanvasPoint { x: -3.0, y: 7.0 },
        ),
    )
    .expect("right-button pan");
    assert_eq!(
        accepted,
        ViewportGestureIntent::Pan {
            kind: ViewportMoveKind::PanDrag,
            request: ViewportPanRequest::new(CanvasPoint { x: -3.0, y: 7.0 }),
        }
    );

    let wrong_button = resolve_viewport_drag_pan_gesture(
        &pan,
        ViewportGestureContext::idle(),
        ViewportDragPanInput::new(
            ViewportPointerButton::Middle,
            CanvasPoint { x: -3.0, y: 7.0 },
        ),
    )
    .expect_err("middle button is disabled");
    assert_eq!(
        wrong_button,
        ViewportGestureRejection::PanOnDragButtonDisabled
    );

    let connection_block = resolve_viewport_drag_pan_gesture(
        &pan,
        ViewportGestureContext {
            connection_in_progress: true,
            ..ViewportGestureContext::idle()
        },
        ViewportDragPanInput::new(
            ViewportPointerButton::Right,
            CanvasPoint { x: -3.0, y: 7.0 },
        ),
    )
    .expect_err("connection gestures block drag-pan");
    assert_eq!(
        connection_block,
        ViewportGestureRejection::ConnectionInProgress
    );

    let selection_block = resolve_viewport_drag_pan_gesture(
        &pan,
        ViewportGestureContext {
            user_selection_active: true,
            ..ViewportGestureContext::idle()
        },
        ViewportDragPanInput::new(
            ViewportPointerButton::Right,
            CanvasPoint { x: -3.0, y: 7.0 },
        ),
    )
    .expect_err("selection gestures block drag-pan");
    assert_eq!(
        selection_block,
        ViewportGestureRejection::UserSelectionActive
    );
}

#[test]
fn pan_activation_key_enables_drag_and_scroll_like_xyflow() {
    let state = NodeGraphInteractionState {
        pan_on_scroll: false,
        pan_on_drag: NodeGraphPanOnDragButtons::default(),
        zoom_on_scroll: false,
        zoom_on_pinch: false,
        zoom_on_double_click: false,
        ..NodeGraphInteractionState::default()
    };
    let context = ViewportGestureContext {
        pan_activation_key_pressed: true,
        ..ViewportGestureContext::idle()
    };

    let scroll = resolve_viewport_scroll_gesture(
        &state.pan_interaction(),
        &state.zoom_interaction(),
        context,
        ViewportScrollInput::new(
            CanvasPoint { x: 8.0, y: 2.0 },
            CanvasPoint { x: 20.0, y: 10.0 },
            false,
            2.0,
            0.25,
            4.0,
        ),
    )
    .expect("pan activation key enables pan-on-scroll");
    assert_eq!(scroll.move_kind(), ViewportMoveKind::PanScroll);

    let drag = resolve_viewport_drag_pan_gesture(
        &state.pan_interaction(),
        context,
        ViewportDragPanInput::new(ViewportPointerButton::Left, CanvasPoint { x: 2.0, y: 3.0 }),
    )
    .expect("pan activation key enables left-button drag pan");
    assert_eq!(drag.move_kind(), ViewportMoveKind::PanDrag);

    let right_click = resolve_viewport_drag_pan_gesture(
        &state.pan_interaction(),
        context,
        ViewportDragPanInput::new(ViewportPointerButton::Right, CanvasPoint { x: 2.0, y: 3.0 }),
    )
    .expect_err("XyFlow activation-key pan does not enable right-click pan");
    assert_eq!(
        right_click,
        ViewportGestureRejection::PanOnDragButtonDisabled
    );
}

#[test]
fn selection_key_pressed_suppresses_drag_pan_without_blocking_scroll() {
    let state = NodeGraphInteractionState {
        pan_on_scroll: true,
        pan_on_drag: NodeGraphPanOnDragButtons {
            left: true,
            middle: false,
            right: false,
        },
        zoom_on_scroll: false,
        zoom_on_pinch: false,
        zoom_on_double_click: false,
        ..NodeGraphInteractionState::default()
    };
    let context = ViewportGestureContext {
        selection_key_pressed: true,
        ..ViewportGestureContext::idle()
    };

    let drag = resolve_viewport_drag_pan_gesture(
        &state.pan_interaction(),
        context,
        ViewportDragPanInput::new(ViewportPointerButton::Left, CanvasPoint { x: 2.0, y: 3.0 }),
    )
    .expect_err("selection key lets selection claim drag gestures");
    assert_eq!(drag, ViewportGestureRejection::PanOnDragDisabled);

    let scroll = resolve_viewport_scroll_gesture(
        &state.pan_interaction(),
        &state.zoom_interaction(),
        context,
        ViewportScrollInput::new(
            CanvasPoint { x: 8.0, y: 2.0 },
            CanvasPoint { x: 20.0, y: 10.0 },
            false,
            2.0,
            0.25,
            4.0,
        ),
    )
    .expect("selection key alone does not mark user selection active");
    assert_eq!(scroll.move_kind(), ViewportMoveKind::PanScroll);
}

#[test]
fn viewport_scroll_policy_reports_disabled_and_selection_rejections() {
    let disabled = NodeGraphInteractionState {
        pan_on_scroll: false,
        pan_on_drag: NodeGraphPanOnDragButtons::default(),
        zoom_on_scroll: false,
        zoom_on_pinch: false,
        zoom_on_double_click: false,
        ..NodeGraphInteractionState::default()
    };
    let input = ViewportScrollInput::new(
        CanvasPoint { x: 1.0, y: 2.0 },
        CanvasPoint { x: 10.0, y: 10.0 },
        false,
        1.5,
        0.25,
        4.0,
    );

    let err = resolve_viewport_scroll_gesture(
        &disabled.pan_interaction(),
        &disabled.zoom_interaction(),
        ViewportGestureContext::idle(),
        input,
    )
    .expect_err("all gestures disabled");
    assert_eq!(err, ViewportGestureRejection::AllViewportGesturesDisabled);

    let state = NodeGraphInteractionState::default();
    let err = resolve_viewport_scroll_gesture(
        &state.pan_interaction(),
        &state.zoom_interaction(),
        ViewportGestureContext {
            user_selection_active: true,
            ..ViewportGestureContext::idle()
        },
        input,
    )
    .expect_err("selection active blocks scroll gestures");
    assert_eq!(err, ViewportGestureRejection::UserSelectionActive);
}

#[test]
fn double_click_zoom_plans_anchored_animation() {
    let state = NodeGraphInteractionState::default();
    let current = ViewportTransform::new(CanvasPoint { x: 10.0, y: 20.0 }, 2.0).unwrap();
    let anchor = CanvasPoint { x: 120.0, y: 60.0 };
    let input = ViewportDoubleClickZoomInput::new(
        current,
        anchor,
        2.0,
        0.5,
        3.0,
        ViewportAnimationOptions::new(0.2).with_easing(ViewportAnimationEasing::Linear),
    );

    let plan = resolve_viewport_double_click_zoom(&state.zoom_interaction(), input)
        .expect("double-click zoom plan");
    let expected_target = zoom_viewport(current, ViewportZoomRequest::new(anchor, 4.0, 0.5, 3.0))
        .expect("anchored target");

    assert_eq!(plan.from, current);
    assert_eq!(plan.to, expected_target);
    assert_eq!(plan.duration_seconds, 0.2);
    assert_eq!(plan.easing, ViewportAnimationEasing::Linear);
    assert_eq!(
        current.canvas_point_at_screen(anchor),
        plan.to.canvas_point_at_screen(anchor),
    );

    let midpoint = plan.frame_at(0.1).expect("midpoint frame");
    assert_eq!(midpoint.progress, 0.5);
    assert_eq!(midpoint.eased_progress, 0.5);
}

#[test]
fn double_click_zoom_respects_policy_and_rejects_invalid_input() {
    let disabled = NodeGraphInteractionState {
        zoom_on_double_click: false,
        ..NodeGraphInteractionState::default()
    };
    let current = ViewportTransform::new(CanvasPoint::default(), 1.0).unwrap();
    let input = ViewportDoubleClickZoomInput::new(
        current,
        CanvasPoint { x: 10.0, y: 10.0 },
        2.0,
        0.5,
        4.0,
        ViewportAnimationOptions::new(0.2),
    );

    let err = resolve_viewport_double_click_zoom(&disabled.zoom_interaction(), input)
        .expect_err("double-click zoom disabled");
    assert_eq!(err, ViewportGestureRejection::DoubleClickZoomDisabled);

    let state = NodeGraphInteractionState::default();
    let invalid_factor = ViewportDoubleClickZoomInput::new(
        current,
        CanvasPoint { x: 10.0, y: 10.0 },
        0.0,
        0.5,
        4.0,
        ViewportAnimationOptions::new(0.2),
    );
    let err = resolve_viewport_double_click_zoom(&state.zoom_interaction(), invalid_factor)
        .expect_err("factor must be positive");
    assert_eq!(err, ViewportGestureRejection::InvalidInput);

    let invalid_anchor = ViewportDoubleClickZoomInput::new(
        current,
        CanvasPoint {
            x: f32::NAN,
            y: 10.0,
        },
        2.0,
        0.5,
        4.0,
        ViewportAnimationOptions::new(0.2),
    );
    let err = resolve_viewport_double_click_zoom(&state.zoom_interaction(), invalid_anchor)
        .expect_err("anchor must be finite");
    assert_eq!(err, ViewportGestureRejection::InvalidInput);
}