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