@wix/interact 1.101.0 → 1.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2268,5 +2268,471 @@ describe('interact', () => {
2268
2268
  expect(mockAnimation.play).toHaveBeenCalled();
2269
2269
  });
2270
2270
  });
2271
+ describe('templated (interpolated) keys', () => {
2272
+ function createEl() {
2273
+ const el = document.createElement('interact-element');
2274
+ const div = document.createElement('div');
2275
+ el.append(div);
2276
+ return [el, div];
2277
+ }
2278
+ describe('one-to-one: single source template to single target template', () => {
2279
+ const getConfig = () => ({
2280
+ interactions: [{
2281
+ trigger: 'click',
2282
+ key: 'src[]',
2283
+ effects: [{
2284
+ key: 'tgt[]',
2285
+ effectId: 'oto-effect'
2286
+ }]
2287
+ }],
2288
+ effects: {
2289
+ 'oto-effect': {
2290
+ namedEffect: {
2291
+ type: 'FadeIn',
2292
+ power: 'medium'
2293
+ },
2294
+ duration: 500
2295
+ }
2296
+ }
2297
+ });
2298
+ it('should bind each source instance to its matching target instance', () => {
2299
+ const {
2300
+ getWebAnimation
2301
+ } = require('@wix/motion');
2302
+ Interact.create(getConfig());
2303
+ const [srcEl0, srcDiv0] = createEl();
2304
+ const [tgtEl0, tgtDiv0] = createEl();
2305
+ const [srcEl1, srcDiv1] = createEl();
2306
+ const [tgtEl1, tgtDiv1] = createEl();
2307
+ const srcSpy0 = jest.spyOn(srcDiv0, 'addEventListener');
2308
+ const srcSpy1 = jest.spyOn(srcDiv1, 'addEventListener');
2309
+ add(srcEl0, 'src[0]');
2310
+ add(tgtEl0, 'tgt[0]');
2311
+ add(srcEl1, 'src[1]');
2312
+ add(tgtEl1, 'tgt[1]');
2313
+ expect(getWebAnimation).toHaveBeenCalledTimes(2);
2314
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv0, expect.objectContaining({
2315
+ namedEffect: expect.objectContaining({
2316
+ type: 'FadeIn'
2317
+ })
2318
+ }), undefined, {
2319
+ reducedMotion: false
2320
+ });
2321
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv1, expect.objectContaining({
2322
+ namedEffect: expect.objectContaining({
2323
+ type: 'FadeIn'
2324
+ })
2325
+ }), undefined, {
2326
+ reducedMotion: false
2327
+ });
2328
+ expect(srcSpy0).toHaveBeenCalledWith('click', expect.any(Function), expect.any(Object));
2329
+ expect(srcSpy1).toHaveBeenCalledWith('click', expect.any(Function), expect.any(Object));
2330
+ });
2331
+ it('should not cross-contaminate between different instance indices', () => {
2332
+ const {
2333
+ getWebAnimation
2334
+ } = require('@wix/motion');
2335
+ Interact.create(getConfig());
2336
+ const [srcEl0] = createEl();
2337
+ const [tgtEl1] = createEl();
2338
+ add(srcEl0, 'src[0]');
2339
+ add(tgtEl1, 'tgt[1]');
2340
+ expect(getWebAnimation).not.toHaveBeenCalled();
2341
+ });
2342
+ it('should work when targets are added before sources', () => {
2343
+ const {
2344
+ getWebAnimation
2345
+ } = require('@wix/motion');
2346
+ Interact.create(getConfig());
2347
+ const [srcEl0] = createEl();
2348
+ const [tgtEl0, tgtDiv0] = createEl();
2349
+ add(tgtEl0, 'tgt[0]');
2350
+ add(srcEl0, 'src[0]');
2351
+ expect(getWebAnimation).toHaveBeenCalledTimes(1);
2352
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv0, expect.objectContaining({
2353
+ namedEffect: expect.objectContaining({
2354
+ type: 'FadeIn'
2355
+ })
2356
+ }), undefined, {
2357
+ reducedMotion: false
2358
+ });
2359
+ });
2360
+ });
2361
+ describe('one-to-many: single source template to multiple target templates', () => {
2362
+ const getConfig = () => ({
2363
+ interactions: [{
2364
+ trigger: 'click',
2365
+ key: 'src[]',
2366
+ effects: [{
2367
+ key: 'tgt-a[]',
2368
+ effectId: 'otm-effect-a'
2369
+ }, {
2370
+ key: 'tgt-b[]',
2371
+ effectId: 'otm-effect-b'
2372
+ }]
2373
+ }],
2374
+ effects: {
2375
+ 'otm-effect-a': {
2376
+ namedEffect: {
2377
+ type: 'FadeIn',
2378
+ power: 'medium'
2379
+ },
2380
+ duration: 500
2381
+ },
2382
+ 'otm-effect-b': {
2383
+ namedEffect: {
2384
+ type: 'BounceIn',
2385
+ power: 'hard',
2386
+ direction: 'center'
2387
+ },
2388
+ duration: 600
2389
+ }
2390
+ }
2391
+ });
2392
+ it('should bind a source instance to all of its target instances', () => {
2393
+ const {
2394
+ getWebAnimation
2395
+ } = require('@wix/motion');
2396
+ Interact.create(getConfig());
2397
+ const [srcEl0, srcDiv0] = createEl();
2398
+ const [tgtAEl0, tgtADiv0] = createEl();
2399
+ const [tgtBEl0, tgtBDiv0] = createEl();
2400
+ const srcSpy = jest.spyOn(srcDiv0, 'addEventListener');
2401
+ add(srcEl0, 'src[0]');
2402
+ add(tgtAEl0, 'tgt-a[0]');
2403
+ add(tgtBEl0, 'tgt-b[0]');
2404
+ expect(getWebAnimation).toHaveBeenCalledTimes(2);
2405
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtADiv0, expect.objectContaining({
2406
+ namedEffect: expect.objectContaining({
2407
+ type: 'FadeIn'
2408
+ })
2409
+ }), undefined, {
2410
+ reducedMotion: false
2411
+ });
2412
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtBDiv0, expect.objectContaining({
2413
+ namedEffect: expect.objectContaining({
2414
+ type: 'BounceIn'
2415
+ })
2416
+ }), undefined, {
2417
+ reducedMotion: false
2418
+ });
2419
+ expect(srcSpy).toHaveBeenCalledWith('click', expect.any(Function), expect.any(Object));
2420
+ });
2421
+ it('should independently wire separate instances to their own targets', () => {
2422
+ const {
2423
+ getWebAnimation
2424
+ } = require('@wix/motion');
2425
+ Interact.create(getConfig());
2426
+ const [srcEl0] = createEl();
2427
+ const [srcEl1] = createEl();
2428
+ const [tgtAEl0, tgtADiv0] = createEl();
2429
+ const [tgtBEl0, tgtBDiv0] = createEl();
2430
+ const [tgtAEl1, tgtADiv1] = createEl();
2431
+ const [tgtBEl1, tgtBDiv1] = createEl();
2432
+ add(srcEl0, 'src[0]');
2433
+ add(srcEl1, 'src[1]');
2434
+ add(tgtAEl0, 'tgt-a[0]');
2435
+ add(tgtBEl0, 'tgt-b[0]');
2436
+ add(tgtAEl1, 'tgt-a[1]');
2437
+ add(tgtBEl1, 'tgt-b[1]');
2438
+ expect(getWebAnimation).toHaveBeenCalledTimes(4);
2439
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtADiv0, expect.objectContaining({
2440
+ namedEffect: expect.objectContaining({
2441
+ type: 'FadeIn'
2442
+ })
2443
+ }), undefined, {
2444
+ reducedMotion: false
2445
+ });
2446
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtBDiv0, expect.objectContaining({
2447
+ namedEffect: expect.objectContaining({
2448
+ type: 'BounceIn'
2449
+ })
2450
+ }), undefined, {
2451
+ reducedMotion: false
2452
+ });
2453
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtADiv1, expect.objectContaining({
2454
+ namedEffect: expect.objectContaining({
2455
+ type: 'FadeIn'
2456
+ })
2457
+ }), undefined, {
2458
+ reducedMotion: false
2459
+ });
2460
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtBDiv1, expect.objectContaining({
2461
+ namedEffect: expect.objectContaining({
2462
+ type: 'BounceIn'
2463
+ })
2464
+ }), undefined, {
2465
+ reducedMotion: false
2466
+ });
2467
+ });
2468
+ });
2469
+ describe('many-to-one: multiple source templates to single target template', () => {
2470
+ const getConfig = () => ({
2471
+ interactions: [{
2472
+ trigger: 'click',
2473
+ key: 'src-a[]',
2474
+ effects: [{
2475
+ key: 'tgt[]',
2476
+ effectId: 'mto-effect-a'
2477
+ }]
2478
+ }, {
2479
+ trigger: 'click',
2480
+ key: 'src-b[]',
2481
+ effects: [{
2482
+ key: 'tgt[]',
2483
+ effectId: 'mto-effect-b'
2484
+ }]
2485
+ }],
2486
+ effects: {
2487
+ 'mto-effect-a': {
2488
+ namedEffect: {
2489
+ type: 'FadeIn',
2490
+ power: 'medium'
2491
+ },
2492
+ duration: 500
2493
+ },
2494
+ 'mto-effect-b': {
2495
+ namedEffect: {
2496
+ type: 'BounceIn',
2497
+ power: 'hard',
2498
+ direction: 'center'
2499
+ },
2500
+ duration: 600
2501
+ }
2502
+ }
2503
+ });
2504
+ it('should bind multiple sources to the same target for a given instance', () => {
2505
+ const {
2506
+ getWebAnimation
2507
+ } = require('@wix/motion');
2508
+ Interact.create(getConfig());
2509
+ const [srcAEl0, srcADiv0] = createEl();
2510
+ const [srcBEl0, srcBDiv0] = createEl();
2511
+ const [tgtEl0, tgtDiv0] = createEl();
2512
+ const srcASpy = jest.spyOn(srcADiv0, 'addEventListener');
2513
+ const srcBSpy = jest.spyOn(srcBDiv0, 'addEventListener');
2514
+ add(srcAEl0, 'src-a[0]');
2515
+ add(srcBEl0, 'src-b[0]');
2516
+ add(tgtEl0, 'tgt[0]');
2517
+ expect(getWebAnimation).toHaveBeenCalledTimes(2);
2518
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv0, expect.objectContaining({
2519
+ namedEffect: expect.objectContaining({
2520
+ type: 'FadeIn'
2521
+ })
2522
+ }), undefined, {
2523
+ reducedMotion: false
2524
+ });
2525
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv0, expect.objectContaining({
2526
+ namedEffect: expect.objectContaining({
2527
+ type: 'BounceIn'
2528
+ })
2529
+ }), undefined, {
2530
+ reducedMotion: false
2531
+ });
2532
+ expect(srcASpy).toHaveBeenCalledWith('click', expect.any(Function), expect.any(Object));
2533
+ expect(srcBSpy).toHaveBeenCalledWith('click', expect.any(Function), expect.any(Object));
2534
+ });
2535
+ it('should isolate different instance indices', () => {
2536
+ const {
2537
+ getWebAnimation
2538
+ } = require('@wix/motion');
2539
+ Interact.create(getConfig());
2540
+ const [srcAEl0] = createEl();
2541
+ const [srcBEl0] = createEl();
2542
+ const [tgtEl0, tgtDiv0] = createEl();
2543
+ const [srcAEl1] = createEl();
2544
+ const [srcBEl1] = createEl();
2545
+ const [tgtEl1, tgtDiv1] = createEl();
2546
+ add(srcAEl0, 'src-a[0]');
2547
+ add(srcBEl0, 'src-b[0]');
2548
+ add(tgtEl0, 'tgt[0]');
2549
+ add(srcAEl1, 'src-a[1]');
2550
+ add(srcBEl1, 'src-b[1]');
2551
+ add(tgtEl1, 'tgt[1]');
2552
+ expect(getWebAnimation).toHaveBeenCalledTimes(4);
2553
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv0, expect.objectContaining({
2554
+ namedEffect: expect.objectContaining({
2555
+ type: 'FadeIn'
2556
+ })
2557
+ }), undefined, {
2558
+ reducedMotion: false
2559
+ });
2560
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv0, expect.objectContaining({
2561
+ namedEffect: expect.objectContaining({
2562
+ type: 'BounceIn'
2563
+ })
2564
+ }), undefined, {
2565
+ reducedMotion: false
2566
+ });
2567
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv1, expect.objectContaining({
2568
+ namedEffect: expect.objectContaining({
2569
+ type: 'FadeIn'
2570
+ })
2571
+ }), undefined, {
2572
+ reducedMotion: false
2573
+ });
2574
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtDiv1, expect.objectContaining({
2575
+ namedEffect: expect.objectContaining({
2576
+ type: 'BounceIn'
2577
+ })
2578
+ }), undefined, {
2579
+ reducedMotion: false
2580
+ });
2581
+ });
2582
+ });
2583
+ describe('many-to-many: multiple source templates to multiple target templates', () => {
2584
+ const getConfig = () => ({
2585
+ interactions: [{
2586
+ trigger: 'click',
2587
+ key: 'src-a[]',
2588
+ effects: [{
2589
+ key: 'tgt-x[]',
2590
+ effectId: 'mtm-ax'
2591
+ }, {
2592
+ key: 'tgt-y[]',
2593
+ effectId: 'mtm-ay'
2594
+ }]
2595
+ }, {
2596
+ trigger: 'click',
2597
+ key: 'src-b[]',
2598
+ effects: [{
2599
+ key: 'tgt-x[]',
2600
+ effectId: 'mtm-bx'
2601
+ }, {
2602
+ key: 'tgt-y[]',
2603
+ effectId: 'mtm-by'
2604
+ }]
2605
+ }],
2606
+ effects: {
2607
+ 'mtm-ax': {
2608
+ namedEffect: {
2609
+ type: 'FadeIn',
2610
+ power: 'soft'
2611
+ },
2612
+ duration: 300
2613
+ },
2614
+ 'mtm-ay': {
2615
+ namedEffect: {
2616
+ type: 'SlideIn',
2617
+ direction: 'left',
2618
+ power: 'medium'
2619
+ },
2620
+ duration: 400
2621
+ },
2622
+ 'mtm-bx': {
2623
+ namedEffect: {
2624
+ type: 'BounceIn',
2625
+ direction: 'center',
2626
+ power: 'hard'
2627
+ },
2628
+ duration: 500
2629
+ },
2630
+ 'mtm-by': {
2631
+ namedEffect: {
2632
+ type: 'Poke',
2633
+ direction: 'right',
2634
+ power: 'medium'
2635
+ },
2636
+ duration: 600
2637
+ }
2638
+ }
2639
+ });
2640
+ it('should bind each source to all of its targets for a given instance', () => {
2641
+ const {
2642
+ getWebAnimation
2643
+ } = require('@wix/motion');
2644
+ Interact.create(getConfig());
2645
+ const [srcAEl0] = createEl();
2646
+ const [srcBEl0] = createEl();
2647
+ const [tgtXEl0, tgtXDiv0] = createEl();
2648
+ const [tgtYEl0, tgtYDiv0] = createEl();
2649
+ add(srcAEl0, 'src-a[0]');
2650
+ add(srcBEl0, 'src-b[0]');
2651
+ add(tgtXEl0, 'tgt-x[0]');
2652
+ add(tgtYEl0, 'tgt-y[0]');
2653
+ expect(getWebAnimation).toHaveBeenCalledTimes(4);
2654
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtXDiv0, expect.objectContaining({
2655
+ namedEffect: expect.objectContaining({
2656
+ type: 'FadeIn'
2657
+ })
2658
+ }), undefined, {
2659
+ reducedMotion: false
2660
+ });
2661
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtYDiv0, expect.objectContaining({
2662
+ namedEffect: expect.objectContaining({
2663
+ type: 'SlideIn'
2664
+ })
2665
+ }), undefined, {
2666
+ reducedMotion: false
2667
+ });
2668
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtXDiv0, expect.objectContaining({
2669
+ namedEffect: expect.objectContaining({
2670
+ type: 'BounceIn'
2671
+ })
2672
+ }), undefined, {
2673
+ reducedMotion: false
2674
+ });
2675
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtYDiv0, expect.objectContaining({
2676
+ namedEffect: expect.objectContaining({
2677
+ type: 'Poke'
2678
+ })
2679
+ }), undefined, {
2680
+ reducedMotion: false
2681
+ });
2682
+ });
2683
+ it('should isolate many-to-many bindings across instance indices', () => {
2684
+ const {
2685
+ getWebAnimation
2686
+ } = require('@wix/motion');
2687
+ Interact.create(getConfig());
2688
+ const [srcAEl0] = createEl();
2689
+ const [srcBEl0] = createEl();
2690
+ const [tgtXEl0, tgtXDiv0] = createEl();
2691
+ const [tgtYEl0, tgtYDiv0] = createEl();
2692
+ add(srcAEl0, 'src-a[0]');
2693
+ add(srcBEl0, 'src-b[0]');
2694
+ add(tgtXEl0, 'tgt-x[0]');
2695
+ add(tgtYEl0, 'tgt-y[0]');
2696
+ expect(getWebAnimation).toHaveBeenCalledTimes(4);
2697
+ const [srcAEl1] = createEl();
2698
+ const [srcBEl1] = createEl();
2699
+ const [tgtXEl1, tgtXDiv1] = createEl();
2700
+ const [tgtYEl1, tgtYDiv1] = createEl();
2701
+ add(srcAEl1, 'src-a[1]');
2702
+ add(srcBEl1, 'src-b[1]');
2703
+ add(tgtXEl1, 'tgt-x[1]');
2704
+ add(tgtYEl1, 'tgt-y[1]');
2705
+ expect(getWebAnimation).toHaveBeenCalledTimes(8);
2706
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtXDiv1, expect.objectContaining({
2707
+ namedEffect: expect.objectContaining({
2708
+ type: 'FadeIn'
2709
+ })
2710
+ }), undefined, {
2711
+ reducedMotion: false
2712
+ });
2713
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtYDiv1, expect.objectContaining({
2714
+ namedEffect: expect.objectContaining({
2715
+ type: 'SlideIn'
2716
+ })
2717
+ }), undefined, {
2718
+ reducedMotion: false
2719
+ });
2720
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtXDiv1, expect.objectContaining({
2721
+ namedEffect: expect.objectContaining({
2722
+ type: 'BounceIn'
2723
+ })
2724
+ }), undefined, {
2725
+ reducedMotion: false
2726
+ });
2727
+ expect(getWebAnimation).toHaveBeenCalledWith(tgtYDiv1, expect.objectContaining({
2728
+ namedEffect: expect.objectContaining({
2729
+ type: 'Poke'
2730
+ })
2731
+ }), undefined, {
2732
+ reducedMotion: false
2733
+ });
2734
+ });
2735
+ });
2736
+ });
2271
2737
  });
2272
2738
  //# sourceMappingURL=interact.spec.js.map