@wiajs/core 1.0.10 → 1.0.11

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.
package/dist/core.cmn.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.0.9
2
+ * wia core v1.0.10
3
3
  * (c) 2015-2023 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -2163,7 +2163,8 @@ const Resize = {
2163
2163
  };
2164
2164
 
2165
2165
  /**
2166
- * document 绑定click事件
2166
+ * document 绑定click事件,传递到 app.on
2167
+ * 触发所有子模块的 clicks
2167
2168
  * 支持touch则绑定touch,否则绑定click
2168
2169
  * 无论touch 还是 click事件,都会触发事件响应函数
2169
2170
  * @param {*} cb
@@ -2254,6 +2255,556 @@ const Click = {
2254
2255
  },
2255
2256
  };
2256
2257
 
2258
+ /* eslint-disable no-nested-ternary */
2259
+
2260
+
2261
+ const {extend: extend$1} = Utils;
2262
+ const {device: device$1, support: support$1} = $;
2263
+
2264
+ function initTouch() {
2265
+ const app = this;
2266
+ const params = app.params.touch;
2267
+ const useRipple = params[`${app.theme}TouchRipple`];
2268
+
2269
+ if (device$1.ios && device$1.webView) {
2270
+ // Strange hack required for iOS 8 webview to work on inputs
2271
+ window.addEventListener('touchstart', () => {});
2272
+ }
2273
+
2274
+ let touchStartX;
2275
+ let touchStartY;
2276
+ let targetElement;
2277
+ let isMoved;
2278
+ let tapHoldFired;
2279
+ let tapHoldTimeout;
2280
+ let preventClick;
2281
+
2282
+ let activableElement;
2283
+ let activeTimeout;
2284
+
2285
+ let rippleWave;
2286
+ let rippleTarget;
2287
+ let rippleTimeout;
2288
+
2289
+ function findActivableElement(el) {
2290
+ const target = $(el);
2291
+ const parents = target.parents(params.activeStateElements);
2292
+ if (target.closest('.no-active-state').length) {
2293
+ return null;
2294
+ }
2295
+ let activable;
2296
+ if (target.is(params.activeStateElements)) {
2297
+ activable = target;
2298
+ }
2299
+ if (parents.length > 0) {
2300
+ activable = activable ? activable.add(parents) : parents;
2301
+ }
2302
+ if (activable && activable.length > 1) {
2303
+ const newActivable = [];
2304
+ let preventPropagation;
2305
+ for (let i = 0; i < activable.length; i += 1) {
2306
+ if (!preventPropagation) {
2307
+ newActivable.push(activable[i]);
2308
+ if (
2309
+ activable.eq(i).hasClass('prevent-active-state-propagation') ||
2310
+ activable.eq(i).hasClass('no-active-state-propagation')
2311
+ ) {
2312
+ preventPropagation = true;
2313
+ }
2314
+ }
2315
+ }
2316
+ activable = $(newActivable);
2317
+ }
2318
+ return activable || target;
2319
+ }
2320
+
2321
+ function isInsideScrollableView(el) {
2322
+ const pageContent = el.parents('.page-content');
2323
+ return pageContent.length > 0;
2324
+ }
2325
+
2326
+ function addActive() {
2327
+ if (!activableElement) return;
2328
+ activableElement.addClass('active-state');
2329
+ }
2330
+ function removeActive() {
2331
+ if (!activableElement) return;
2332
+ activableElement.removeClass('active-state');
2333
+ activableElement = null;
2334
+ }
2335
+
2336
+ // Ripple handlers
2337
+ function findRippleElement(el) {
2338
+ const rippleElements = params.touchRippleElements;
2339
+ const $el = $(el);
2340
+ if ($el.is(rippleElements)) {
2341
+ if ($el.hasClass('no-ripple')) {
2342
+ return false;
2343
+ }
2344
+ return $el;
2345
+ }
2346
+ if ($el.parents(rippleElements).length > 0) {
2347
+ const rippleParent = $el.parents(rippleElements).eq(0);
2348
+ if (rippleParent.hasClass('no-ripple')) {
2349
+ return false;
2350
+ }
2351
+ return rippleParent;
2352
+ }
2353
+ return false;
2354
+ }
2355
+
2356
+ function createRipple($el, x, y) {
2357
+ if (!$el) return;
2358
+ rippleWave = app.touchRipple.create(app, $el, x, y);
2359
+ }
2360
+
2361
+ function removeRipple() {
2362
+ if (!rippleWave) return;
2363
+ rippleWave.remove();
2364
+ rippleWave = undefined;
2365
+ rippleTarget = undefined;
2366
+ }
2367
+ function rippleTouchStart(el) {
2368
+ rippleTarget = findRippleElement(el);
2369
+ if (!rippleTarget || rippleTarget.length === 0) {
2370
+ rippleTarget = undefined;
2371
+ return;
2372
+ }
2373
+ const inScrollable = isInsideScrollableView(rippleTarget);
2374
+
2375
+ if (!inScrollable) {
2376
+ removeRipple();
2377
+ createRipple(rippleTarget, touchStartX, touchStartY);
2378
+ } else {
2379
+ clearTimeout(rippleTimeout);
2380
+ rippleTimeout = setTimeout(() => {
2381
+ removeRipple();
2382
+ createRipple(rippleTarget, touchStartX, touchStartY);
2383
+ }, 80);
2384
+ }
2385
+ }
2386
+ function rippleTouchMove() {
2387
+ clearTimeout(rippleTimeout);
2388
+ removeRipple();
2389
+ }
2390
+ function rippleTouchEnd() {
2391
+ if (!rippleWave && rippleTarget && !isMoved) {
2392
+ clearTimeout(rippleTimeout);
2393
+ createRipple(rippleTarget, touchStartX, touchStartY);
2394
+ setTimeout(removeRipple, 0);
2395
+ } else {
2396
+ removeRipple();
2397
+ }
2398
+ }
2399
+
2400
+ // Mouse Handlers
2401
+ function handleMouseDown(e) {
2402
+ const $activableEl = findActivableElement(e.target);
2403
+ if ($activableEl) {
2404
+ $activableEl.addClass('active-state');
2405
+ if ('which' in e && e.which === 3) {
2406
+ setTimeout(() => {
2407
+ $('.active-state').removeClass('active-state');
2408
+ }, 0);
2409
+ }
2410
+ }
2411
+
2412
+ if (useRipple) {
2413
+ touchStartX = e.pageX;
2414
+ touchStartY = e.pageY;
2415
+ rippleTouchStart(e.target, e.pageX, e.pageY);
2416
+ }
2417
+ }
2418
+ function handleMouseMove() {
2419
+ if (!params.activeStateOnMouseMove) {
2420
+ $('.active-state').removeClass('active-state');
2421
+ }
2422
+ if (useRipple) {
2423
+ rippleTouchMove();
2424
+ }
2425
+ }
2426
+ function handleMouseUp() {
2427
+ $('.active-state').removeClass('active-state');
2428
+ if (useRipple) {
2429
+ rippleTouchEnd();
2430
+ }
2431
+ }
2432
+
2433
+ function handleTouchCancel() {
2434
+ targetElement = null;
2435
+
2436
+ // Remove Active State
2437
+ clearTimeout(activeTimeout);
2438
+ clearTimeout(tapHoldTimeout);
2439
+ if (params.activeState) {
2440
+ removeActive();
2441
+ }
2442
+
2443
+ // Remove Ripple
2444
+ if (useRipple) {
2445
+ rippleTouchEnd();
2446
+ }
2447
+ }
2448
+
2449
+ let isScrolling;
2450
+ let isSegmentedStrong = false;
2451
+ let segmentedStrongEl = null;
2452
+
2453
+ const touchMoveActivableIos = '.dialog-button, .actions-button';
2454
+ let isTouchMoveActivable = false;
2455
+ let touchmoveActivableEl = null;
2456
+
2457
+ function handleTouchStart(e) {
2458
+ if (!e.isTrusted) return true;
2459
+ isMoved = false;
2460
+ tapHoldFired = false;
2461
+ preventClick = false;
2462
+ isScrolling = undefined;
2463
+ if (e.targetTouches.length > 1) {
2464
+ if (activableElement) removeActive();
2465
+ return true;
2466
+ }
2467
+ if (e.touches.length > 1 && activableElement) {
2468
+ removeActive();
2469
+ }
2470
+ if (params.tapHold) {
2471
+ if (tapHoldTimeout) clearTimeout(tapHoldTimeout);
2472
+ tapHoldTimeout = setTimeout(() => {
2473
+ if (e && e.touches && e.touches.length > 1) return;
2474
+ tapHoldFired = true;
2475
+ e.preventDefault();
2476
+ preventClick = true;
2477
+ $(e.target).trigger('taphold', e);
2478
+ app.emit('taphold', e);
2479
+ }, params.tapHoldDelay);
2480
+ }
2481
+ targetElement = e.target;
2482
+ touchStartX = e.targetTouches[0].pageX;
2483
+ touchStartY = e.targetTouches[0].pageY;
2484
+ isSegmentedStrong = e.target.closest(
2485
+ '.segmented-strong .button-active, .segmented-strong .tab-link-active'
2486
+ );
2487
+ isTouchMoveActivable = app.theme === 'ios' && e.target.closest(touchMoveActivableIos);
2488
+ if (isSegmentedStrong) {
2489
+ segmentedStrongEl = isSegmentedStrong.closest('.segmented-strong');
2490
+ }
2491
+
2492
+ if (params.activeState) {
2493
+ activableElement = findActivableElement(targetElement);
2494
+ if (activableElement && !isInsideScrollableView(activableElement)) {
2495
+ addActive();
2496
+ } else if (activableElement) {
2497
+ activeTimeout = setTimeout(addActive, 80);
2498
+ }
2499
+ }
2500
+ if (useRipple) {
2501
+ rippleTouchStart(targetElement);
2502
+ }
2503
+ return true;
2504
+ }
2505
+
2506
+ function handleTouchMove(e) {
2507
+ if (!e.isTrusted) return;
2508
+ let touch;
2509
+ let distance;
2510
+ let shouldRemoveActive = true;
2511
+
2512
+ if (e.type === 'touchmove') {
2513
+ touch = e.targetTouches[0];
2514
+ distance = params.touchClicksDistanceThreshold;
2515
+ }
2516
+
2517
+ const touchCurrentX = e.targetTouches[0].pageX;
2518
+ const touchCurrentY = e.targetTouches[0].pageY;
2519
+
2520
+ if (typeof isScrolling === 'undefined') {
2521
+ isScrolling = !!(
2522
+ isScrolling || Math.abs(touchCurrentY - touchStartY) > Math.abs(touchCurrentX - touchStartX)
2523
+ );
2524
+ }
2525
+
2526
+ if (isTouchMoveActivable || (!isScrolling && isSegmentedStrong && segmentedStrongEl)) {
2527
+ if (e.cancelable) e.preventDefault();
2528
+ }
2529
+
2530
+ if (!isScrolling && isSegmentedStrong && segmentedStrongEl) {
2531
+ const elementFromPoint = document.elementFromPoint(
2532
+ e.targetTouches[0].clientX,
2533
+ e.targetTouches[0].clientY
2534
+ );
2535
+ const buttonEl = elementFromPoint.closest(
2536
+ '.segmented-strong .button:not(.button-active):not(.tab-link-active)'
2537
+ );
2538
+ if (buttonEl && segmentedStrongEl.contains(buttonEl)) {
2539
+ $(buttonEl).trigger('click', 'f7Segmented');
2540
+ targetElement = buttonEl;
2541
+ }
2542
+ }
2543
+
2544
+ if (distance && touch) {
2545
+ const {pageX, pageY} = touch;
2546
+ if (Math.abs(pageX - touchStartX) > distance || Math.abs(pageY - touchStartY) > distance) {
2547
+ isMoved = true;
2548
+ }
2549
+ } else {
2550
+ isMoved = true;
2551
+ }
2552
+
2553
+ if (isMoved) {
2554
+ preventClick = true;
2555
+ // Keep active state on touchMove (for dialog and actions buttons)
2556
+ if (isTouchMoveActivable) {
2557
+ const elementFromPoint = document.elementFromPoint(
2558
+ e.targetTouches[0].clientX,
2559
+ e.targetTouches[0].clientY
2560
+ );
2561
+ touchmoveActivableEl = elementFromPoint.closest(touchMoveActivableIos);
2562
+ if (
2563
+ touchmoveActivableEl &&
2564
+ activableElement &&
2565
+ activableElement[0] === touchmoveActivableEl
2566
+ ) {
2567
+ shouldRemoveActive = false;
2568
+ } else if (touchmoveActivableEl) {
2569
+ setTimeout(() => {
2570
+ activableElement = findActivableElement(touchmoveActivableEl);
2571
+ addActive();
2572
+ });
2573
+ }
2574
+ }
2575
+ if (params.tapHold) {
2576
+ clearTimeout(tapHoldTimeout);
2577
+ }
2578
+ if (params.activeState && shouldRemoveActive) {
2579
+ clearTimeout(activeTimeout);
2580
+ removeActive();
2581
+ }
2582
+ if (useRipple) {
2583
+ rippleTouchMove();
2584
+ }
2585
+ }
2586
+ }
2587
+
2588
+ function handleTouchEnd(e) {
2589
+ if (!e.isTrusted) return true;
2590
+ isScrolling = undefined;
2591
+ isSegmentedStrong = false;
2592
+ segmentedStrongEl = null;
2593
+ isTouchMoveActivable = false;
2594
+ clearTimeout(activeTimeout);
2595
+ clearTimeout(tapHoldTimeout);
2596
+ if (touchmoveActivableEl) {
2597
+ $(touchmoveActivableEl).trigger('click', 'f7TouchMoveActivable');
2598
+ touchmoveActivableEl = null;
2599
+ }
2600
+ if (document.activeElement === e.target) {
2601
+ if (params.activeState) removeActive();
2602
+ if (useRipple) {
2603
+ rippleTouchEnd();
2604
+ }
2605
+ return true;
2606
+ }
2607
+ if (params.activeState) {
2608
+ addActive();
2609
+ setTimeout(removeActive, 0);
2610
+ }
2611
+ if (useRipple) {
2612
+ rippleTouchEnd();
2613
+ }
2614
+ if ((params.tapHoldPreventClicks && tapHoldFired) || preventClick) {
2615
+ if (e.cancelable) e.preventDefault();
2616
+ preventClick = true;
2617
+ return false;
2618
+ }
2619
+ return true;
2620
+ }
2621
+
2622
+ function handleClick(e) {
2623
+ const isOverswipe = e && e.detail && e.detail === 'f7Overswipe';
2624
+ const isSegmented = e && e.detail && e.detail === 'f7Segmented';
2625
+ // eslint-disable-next-line
2626
+ const isTouchMoveActivable = e && e.detail && e.detail === 'f7TouchMoveActivable';
2627
+ let localPreventClick = preventClick;
2628
+ if (targetElement && e.target !== targetElement) {
2629
+ if (isOverswipe || isSegmented || isTouchMoveActivable) {
2630
+ localPreventClick = false;
2631
+ } else {
2632
+ localPreventClick = true;
2633
+ }
2634
+ } else if (isTouchMoveActivable) {
2635
+ localPreventClick = false;
2636
+ }
2637
+ if (params.tapHold && params.tapHoldPreventClicks && tapHoldFired) {
2638
+ localPreventClick = true;
2639
+ }
2640
+ if (localPreventClick) {
2641
+ e.stopImmediatePropagation();
2642
+ e.stopPropagation();
2643
+ e.preventDefault();
2644
+ }
2645
+
2646
+ if (params.tapHold) {
2647
+ tapHoldTimeout = setTimeout(
2648
+ () => {
2649
+ tapHoldFired = false;
2650
+ },
2651
+ device$1.ios || device$1.androidChrome ? 100 : 400
2652
+ );
2653
+ }
2654
+ preventClick = false;
2655
+ targetElement = null;
2656
+
2657
+ return !localPreventClick;
2658
+ }
2659
+
2660
+ /**
2661
+ * document touch �¼����ݸ� app.on
2662
+ * @param {*} name
2663
+ * @param {*} e
2664
+ */
2665
+ function emitAppTouchEvent(name, e) {
2666
+ app.emit({
2667
+ events: name,
2668
+ data: [e],
2669
+ });
2670
+ }
2671
+
2672
+ function appTouchStartActive(e) {
2673
+ emitAppTouchEvent('touchstart touchstart:active', e);
2674
+ }
2675
+
2676
+ function appTouchMoveActive(e) {
2677
+ emitAppTouchEvent('touchmove touchmove:active', e);
2678
+ }
2679
+
2680
+ function appTouchEndActive(e) {
2681
+ emitAppTouchEvent('touchend touchend:active', e);
2682
+ }
2683
+
2684
+ function appTouchStartPassive(e) {
2685
+ emitAppTouchEvent('touchstart:passive', e);
2686
+ }
2687
+
2688
+ function appTouchMovePassive(e) {
2689
+ emitAppTouchEvent('touchmove:passive', e);
2690
+ }
2691
+
2692
+ function appTouchEndPassive(e) {
2693
+ emitAppTouchEvent('touchend:passive', e);
2694
+ }
2695
+
2696
+ const passiveListener = support$1.passiveListener ? {passive: true} : false;
2697
+ const passiveListenerCapture = support$1.passiveListener ? {passive: true, capture: true} : true;
2698
+ const activeListener = support$1.passiveListener ? {passive: false} : false;
2699
+ const activeListenerCapture = support$1.passiveListener ? {passive: false, capture: true} : true;
2700
+
2701
+ // document touch �¼� ���ݸ� app.on
2702
+ if (support$1.passiveListener) {
2703
+ document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListenerCapture);
2704
+ document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
2705
+ document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
2706
+
2707
+ document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListenerCapture);
2708
+ document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
2709
+ document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
2710
+ } else {
2711
+ document.addEventListener(
2712
+ app.touchEvents.start,
2713
+ e => {
2714
+ appTouchStartActive(e);
2715
+ appTouchStartPassive(e);
2716
+ },
2717
+ true
2718
+ );
2719
+ document.addEventListener(
2720
+ app.touchEvents.move,
2721
+ e => {
2722
+ appTouchMoveActive(e);
2723
+ appTouchMovePassive(e);
2724
+ },
2725
+ false
2726
+ );
2727
+ document.addEventListener(
2728
+ app.touchEvents.end,
2729
+ e => {
2730
+ appTouchEndActive(e);
2731
+ appTouchEndPassive(e);
2732
+ },
2733
+ false
2734
+ );
2735
+ }
2736
+
2737
+ if (support$1.touch) {
2738
+ app.on('click', handleClick);
2739
+ app.on('touchstart', handleTouchStart);
2740
+ app.on('touchmove', handleTouchMove);
2741
+ app.on('touchend', handleTouchEnd);
2742
+ document.addEventListener('touchcancel', handleTouchCancel, {passive: true});
2743
+ } else if (params.activeState) {
2744
+ app.on('touchstart', handleMouseDown);
2745
+ app.on('touchmove', handleMouseMove);
2746
+ app.on('touchend', handleMouseUp);
2747
+ document.addEventListener('pointercancel', handleMouseUp, {passive: true});
2748
+ }
2749
+
2750
+ document.addEventListener('contextmenu', e => {
2751
+ if (
2752
+ params.disableContextMenu &&
2753
+ (device$1.ios ||
2754
+ device$1.android ||
2755
+ device$1.cordova ||
2756
+ (window.Capacitor && window.Capacitor.isNative))
2757
+ ) {
2758
+ e.preventDefault();
2759
+ }
2760
+ if (useRipple) {
2761
+ if (activableElement) removeActive();
2762
+ rippleTouchEnd();
2763
+ }
2764
+ });
2765
+ }
2766
+
2767
+ const Touch = {
2768
+ name: 'touch',
2769
+ params: {
2770
+ touch: {
2771
+ // Clicks
2772
+ touchClicksDistanceThreshold: 5,
2773
+ // ContextMenu
2774
+ disableContextMenu: false,
2775
+ // Tap Hold
2776
+ tapHold: false,
2777
+ tapHoldDelay: 750,
2778
+ tapHoldPreventClicks: true,
2779
+ // Active State
2780
+ activeState: true,
2781
+ activeStateElements:
2782
+ 'a, button, label, span, .actions-button, .stepper-button, .stepper-button-plus, .stepper-button-minus, .card-expandable, .link, .item-link, .accordion-item-toggle',
2783
+ activeStateOnMouseMove: false,
2784
+ mdTouchRipple: true,
2785
+ iosTouchRipple: false,
2786
+ touchRippleElements:
2787
+ '.ripple, .link, .item-link, .list label.item-content, .list-button, .links-list a, .button, button, .input-clear-button, .dialog-button, .tab-link, .item-radio, .item-checkbox, .actions-button, .searchbar-disable-button, .fab a, .checkbox, .radio, .data-table .sortable-cell:not(.input-cell), .notification-close-button, .stepper-button, .stepper-button-minus, .stepper-button-plus, .list.accordion-list .accordion-item-toggle',
2788
+ touchRippleInsetElements:
2789
+ '.ripple-inset, .icon-only, .searchbar-disable-button, .input-clear-button, .notification-close-button, .md .navbar .link.back',
2790
+ },
2791
+ },
2792
+
2793
+ create() {
2794
+ const app = this;
2795
+ extend$1(app, {
2796
+ touchEvents: {
2797
+ start: support$1.touch ? 'touchstart' : support$1.pointerEvents ? 'pointerdown' : 'mousedown',
2798
+ move: support$1.touch ? 'touchmove' : support$1.pointerEvents ? 'pointermove' : 'mousemove',
2799
+ end: support$1.touch ? 'touchend' : support$1.pointerEvents ? 'pointerup' : 'mouseup',
2800
+ },
2801
+ });
2802
+ },
2803
+ on: {
2804
+ init: initTouch,
2805
+ },
2806
+ };
2807
+
2257
2808
  const SW = {
2258
2809
  registrations: [],
2259
2810
  register(path, scope) {
@@ -2853,6 +3404,7 @@ App.utils = Utils;
2853
3404
  App.use([
2854
3405
  Resize, // 控制屏幕大小
2855
3406
  Click, // 触发UI组件的点击(Click 或 Touch)事件
3407
+ Touch, // 触发app.on(Touch事件)
2856
3408
  SW$1, // ServiceWorker
2857
3409
 
2858
3410
  //INSTALL_COMPONENTS