From d82aec1c2a7d4d08eb295dbd154f5254c4b174e1 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Thu, 7 May 2020 17:52:49 +0200 Subject: [PATCH] refactor(core): remove deprecated gesture code Removes the unused gesture code that was deprecated a while ago. BREAKING CHANGES: * `MAT_HAMMER_OPTIONS` has been removed. * `GestureConfig` has been removed. * `HammerInput` has been removed. * `HammerStatic` has been removed. * `Recognizer` has been removed. * `RecognizerStatic` has been removed. * `HammerInstance` has been removed. * `HammerManager` has been removed. * `HammerOptions` has been removed. --- .../core/gestures/gesture-annotations.ts | 97 ------------- src/material/core/gestures/gesture-config.ts | 129 ------------------ src/material/core/public-api.ts | 2 - tools/public_api_guard/material/core.d.ts | 62 --------- 4 files changed, 290 deletions(-) delete mode 100644 src/material/core/gestures/gesture-annotations.ts delete mode 100644 src/material/core/gestures/gesture-config.ts diff --git a/src/material/core/gestures/gesture-annotations.ts b/src/material/core/gestures/gesture-annotations.ts deleted file mode 100644 index 8461b3d31726..000000000000 --- a/src/material/core/gestures/gesture-annotations.ts +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -/** - * Stripped-down HammerJS annotations to be used within Material, which are necessary, - * because HammerJS is an optional dependency. For the full annotations see: - * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/hammerjs/index.d.ts - */ - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface HammerInput { - preventDefault: () => {}; - deltaX: number; - deltaY: number; - center: { x: number; y: number; }; -} - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface HammerStatic { - new(element: HTMLElement | SVGElement, options?: any): HammerManager; - - Pan: Recognizer; - Swipe: Recognizer; - Press: Recognizer; -} - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface Recognizer { - new(options?: any): Recognizer; - recognizeWith(otherRecognizer: Recognizer | string): Recognizer; -} - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface RecognizerStatic { - new(options?: any): Recognizer; -} - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface HammerInstance { - on(eventName: string, callback: Function): void; - off(eventName: string, callback: Function): void; -} - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface HammerManager { - add(recogniser: Recognizer | Recognizer[]): Recognizer; - set(options: any): HammerManager; - emit(event: string, data: any): void; - off(events: string, handler?: Function): void; - on(events: string, handler: Function): void; -} - -/** - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - * @docs-private - */ -export interface HammerOptions { - cssProps?: {[key: string]: string}; - domEvents?: boolean; - enable?: boolean | ((manager: HammerManager) => boolean); - preset?: any[]; - touchAction?: string; - recognizers?: any[]; - - inputClass?: HammerInput; - inputTarget?: EventTarget; -} diff --git a/src/material/core/gestures/gesture-config.ts b/src/material/core/gestures/gesture-config.ts deleted file mode 100644 index 6bcd632e8f33..000000000000 --- a/src/material/core/gestures/gesture-config.ts +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {Injectable, InjectionToken, Inject, Optional} from '@angular/core'; -import {HammerGestureConfig} from '@angular/platform-browser'; -import {MatCommonModule} from '../common-behaviors/common-module'; -import { - HammerStatic, - HammerInstance, - Recognizer, - RecognizerStatic, - HammerOptions, -} from './gesture-annotations'; - -/** - * Injection token that can be used to provide options to the Hammerjs instance. - * More info at http://hammerjs.github.io/api/. - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - */ -export const MAT_HAMMER_OPTIONS = new InjectionToken('MAT_HAMMER_OPTIONS'); - -const ANGULAR_MATERIAL_SUPPORTED_HAMMER_GESTURES = [ - 'longpress', - 'slide', - 'slidestart', - 'slideend', - 'slideright', - 'slideleft' -]; - -/** - * Fake HammerInstance that is used when a Hammer instance is requested when HammerJS has not - * been loaded on the page. - */ -const noopHammerInstance: HammerInstance = { - on: () => {}, - off: () => {}, -}; - -/** - * Adjusts configuration of our gesture library, Hammer. - * @deprecated No longer being used. To be removed. - * @breaking-change 10.0.0 - */ -@Injectable() -export class GestureConfig extends HammerGestureConfig { - /** List of new event names to add to the gesture support list */ - events = ANGULAR_MATERIAL_SUPPORTED_HAMMER_GESTURES; - - constructor( - @Optional() @Inject(MAT_HAMMER_OPTIONS) private _hammerOptions?: HammerOptions, - @Optional() _commonModule?: MatCommonModule) { - super(); - } - - /** - * Builds Hammer instance manually to add custom recognizers that match the Material Design spec. - * - * Our gesture names come from the Material Design gestures spec: - * https://material.io/design/#gestures-touch-mechanics - * - * More information on default recognizers can be found in Hammer docs: - * http://hammerjs.github.io/recognizer-pan/ - * http://hammerjs.github.io/recognizer-press/ - * - * @param element Element to which to assign the new HammerJS gestures. - * @returns Newly-created HammerJS instance. - */ - buildHammer(element: HTMLElement): HammerInstance { - const hammer: HammerStatic = typeof window !== 'undefined' ? (window as any).Hammer : null; - - if (!hammer) { - // If HammerJS is not loaded here, return the noop HammerInstance. This is necessary to - // ensure that omitting HammerJS completely will not cause any errors while *also* supporting - // the lazy-loading of HammerJS via the HAMMER_LOADER token introduced in Angular 6.1. - // Because we can't depend on HAMMER_LOADER's existance until 7.0, we have to always set - // `this.events` to the set we support, instead of conditionally setting it to `[]` if - // `HAMMER_LOADER` is present (and then throwing an Error here if `window.Hammer` is - // undefined). - // @breaking-change 8.0.0 - return noopHammerInstance; - } - - const mc = new hammer(element, this._hammerOptions || undefined); - - // Default Hammer Recognizers. - const pan = new hammer.Pan(); - const swipe = new hammer.Swipe(); - const press = new hammer.Press(); - - // Notice that a HammerJS recognizer can only depend on one other recognizer once. - // Otherwise the previous `recognizeWith` will be dropped. - // TODO: Confirm threshold numbers with Material Design UX Team - const slide = this._createRecognizer(pan, {event: 'slide', threshold: 0}, swipe); - const longpress = this._createRecognizer(press, {event: 'longpress', time: 500}); - - // Overwrite the default `pan` event to use the swipe event. - pan.recognizeWith(swipe); - - // Since the slide event threshold is set to zero, the slide recognizer can fire and - // accidentally reset the longpress recognizer. In order to make sure that the two - // recognizers can run simultaneously but don't affect each other, we allow the slide - // recognizer to recognize while a longpress is being processed. - // See: https://github.com/hammerjs/hammer.js/blob/master/src/manager.js#L123-L124 - longpress.recognizeWith(slide); - - // Add customized gestures to Hammer manager - mc.add([swipe, press, pan, slide, longpress]); - - return mc as HammerInstance; - } - - /** Creates a new recognizer, without affecting the default recognizers of HammerJS */ - private _createRecognizer(base: Recognizer, options: any, ...inheritances: Recognizer[]) { - let recognizer = new (base.constructor as RecognizerStatic)(options); - - inheritances.push(base); - inheritances.forEach(item => recognizer.recognizeWith(item)); - - return recognizer; - } - -} diff --git a/src/material/core/public-api.ts b/src/material/core/public-api.ts index 474ddedf0ea1..1dd2d4932163 100644 --- a/src/material/core/public-api.ts +++ b/src/material/core/public-api.ts @@ -11,8 +11,6 @@ export * from './animation/animation'; export * from './common-behaviors/index'; export * from './datetime/index'; export * from './error/error-options'; -export * from './gestures/gesture-annotations'; -export * from './gestures/gesture-config'; export * from './line/line'; export * from './option/index'; export * from './label/label-options'; diff --git a/tools/public_api_guard/material/core.d.ts b/tools/public_api_guard/material/core.d.ts index 3df5ded1c9d6..d55ad6a42afd 100644 --- a/tools/public_api_guard/material/core.d.ts +++ b/tools/public_api_guard/material/core.d.ts @@ -96,14 +96,6 @@ export declare const JAN = 0, FEB = 1, MAR = 2, APR = 3, MAY = 4, JUN = 5, JUL = export declare type FloatLabelType = 'always' | 'never' | 'auto'; -export declare class GestureConfig extends HammerGestureConfig { - events: string[]; - constructor(_hammerOptions?: HammerOptions | undefined, _commonModule?: MatCommonModule); - buildHammer(element: HTMLElement): HammerInstance; - static ɵfac: i0.ɵɵFactoryDef; - static ɵprov: i0.ɵɵInjectableDef; -} - export interface GranularSanityChecks { doctype: boolean; hammer: boolean; @@ -111,49 +103,6 @@ export interface GranularSanityChecks { version: boolean; } -export interface HammerInput { - center: { - x: number; - y: number; - }; - deltaX: number; - deltaY: number; - preventDefault: () => {}; -} - -export interface HammerInstance { - off(eventName: string, callback: Function): void; - on(eventName: string, callback: Function): void; -} - -export interface HammerManager { - add(recogniser: Recognizer | Recognizer[]): Recognizer; - emit(event: string, data: any): void; - off(events: string, handler?: Function): void; - on(events: string, handler: Function): void; - set(options: any): HammerManager; -} - -export interface HammerOptions { - cssProps?: { - [key: string]: string; - }; - domEvents?: boolean; - enable?: boolean | ((manager: HammerManager) => boolean); - inputClass?: HammerInput; - inputTarget?: EventTarget; - preset?: any[]; - recognizers?: any[]; - touchAction?: string; -} - -export interface HammerStatic { - Pan: Recognizer; - Press: Recognizer; - Swipe: Recognizer; - new (element: HTMLElement | SVGElement, options?: any): HammerManager; -} - export interface HasInitialized { _markInitialized: () => void; initialized: Observable; @@ -190,8 +139,6 @@ export declare const MAT_DATE_LOCALE_PROVIDER: { useExisting: InjectionToken; }; -export declare const MAT_HAMMER_OPTIONS: InjectionToken; - export declare const MAT_LABEL_GLOBAL_OPTIONS: InjectionToken; export declare const MAT_NATIVE_DATE_FORMATS: MatDateFormats; @@ -395,15 +342,6 @@ export declare const JAN = 0, FEB = 1, MAR = 2, APR = 3, MAY = 4, JUN = 5, JUL = export declare const JAN = 0, FEB = 1, MAR = 2, APR = 3, MAY = 4, JUN = 5, JUL = 6, AUG = 7, SEP = 8, OCT = 9, NOV = 10, DEC = 11; -export interface Recognizer { - new (options?: any): Recognizer; - recognizeWith(otherRecognizer: Recognizer | string): Recognizer; -} - -export interface RecognizerStatic { - new (options?: any): Recognizer; -} - export interface RippleAnimationConfig { enterDuration?: number; exitDuration?: number;