Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

refactor: Make TS easier to wrap #4407

Merged
merged 75 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
d4320a3
refactor: Make TS easier to wrap
acdvorak Feb 12, 2019
64d44bd
WIP: Dialog
acdvorak Feb 12, 2019
4b8d7f1
WIP: DOM
acdvorak Feb 12, 2019
9395509
WIP: floating-label
acdvorak Feb 12, 2019
20b4709
WIP: form-field
acdvorak Feb 12, 2019
db04534
WIP: Add missing factory functions
acdvorak Feb 12, 2019
73525f7
WIP: icon-button
acdvorak Feb 12, 2019
80223a1
WIP: Revert accidental renames
acdvorak Feb 12, 2019
7e85e42
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 13, 2019
ff41340
WIP: Fix typo
acdvorak Feb 14, 2019
482c6e1
WIP: Add missing `private` visibility modifier
acdvorak Feb 14, 2019
e9e0e33
WIP: Reorder methods for consistency
acdvorak Feb 14, 2019
a080cda
WIP: Reorder exports
acdvorak Feb 14, 2019
5ef72ad
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 14, 2019
8c5cde8
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 14, 2019
7a35f8b
WIP: Move animation functions into `util.ts`, and export under new `{…
acdvorak Feb 14, 2019
2874cb4
WIP: Remove `export default MDCFoo` from `component.ts` files
acdvorak Feb 14, 2019
2efc895
WIP: Move `externs.d.ts` from `mdc-dom` to `mdc-base`
acdvorak Feb 14, 2019
86a31ce
WIP: Add `/index` to chip import paths for consistency
acdvorak Feb 14, 2019
103f125
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 15, 2019
173f202
fix(feature-targeting): fix incorrect list construction (#4419)
mmalerba Feb 15, 2019
7ed6123
docs(dialog): Expand wording RE layout-sensitive children (#4370)
kfranqueiro Feb 15, 2019
d679b39
fix(infrastructure): Fix GitHub API authentication bug
acdvorak Feb 15, 2019
ed47614
WIP: Fix token format
acdvorak Feb 15, 2019
83300c5
chore: Add @alternate annotation to fix closure sass errors
abhiomkar Feb 15, 2019
ffb24c3
chore: updated for textfield
abhiomkar Feb 15, 2019
f765918
chore: removed redundant styles
abhiomkar Feb 15, 2019
ab90fa5
WIP: Redact auth token from error messages; remove console.log() stat…
acdvorak Feb 15, 2019
94fd587
WIP: Reduce log spam: Don't print unchanged files; don't upload `*.d.…
acdvorak Feb 15, 2019
16764a1
WIP: Remove unnecessary glob exclude
acdvorak Feb 15, 2019
5bdfcfb
WIP: Remove `packages` dir from `npm run lint:js`
acdvorak Feb 15, 2019
3d41e71
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 15, 2019
c015434
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 15, 2019
c0bebff
WIP: Fix `lint:js` by removing `packages` dir
acdvorak Feb 15, 2019
611d78d
WIP: Remove `default` export from adapters
acdvorak Feb 16, 2019
7558e6f
WIP: Add return type to `defaultAdapter()` in `MDCToolbarFoundation`
acdvorak Feb 16, 2019
031da72
WIP: Extract component adapter implementations to strongly-typed vari…
acdvorak Feb 16, 2019
577bec1
WIP: Remove default export from adapters
acdvorak Feb 16, 2019
0831eed
WIP: Clean up component factories
acdvorak Feb 16, 2019
725b7fe
WIP: Extract strongly typed variables for ripple adapters
acdvorak Feb 16, 2019
17a6945
WIP: Break `MDCTextFieldAdapter` into sub-interfaces for readability …
acdvorak Feb 16, 2019
77ce604
WIP: Remove unnecessary types from adapter impls; `root_.addEventList…
acdvorak Feb 16, 2019
4c1138f
WIP: Remove inferred return type; `initRipple_()` -> `createRipple_()`
acdvorak Feb 16, 2019
da08b76
WIP: Add `.ts` extension to testable file check for unit tests
acdvorak Feb 16, 2019
c3a26b3
Merge branch 'feat/typescript--github-api' into feat/typescript--refa…
acdvorak Feb 16, 2019
66d615f
WIP: Move all component definitions to `component.ts` files; standard…
acdvorak Feb 16, 2019
3be46ee
WIP: Add `MDC` prefix to most exported types
acdvorak Feb 16, 2019
835031a
WIP: Use object imports in unit tests instead of default
acdvorak Feb 16, 2019
361edfe
WIP: Remove default exports from components that didn't previously ha…
acdvorak Feb 16, 2019
1e9496d
WIP: Standardize default export syntax in foundations
acdvorak Feb 16, 2019
c1bec4b
WIP: Style
acdvorak Feb 16, 2019
93c7bf3
WIP: Add missing event detail generic type param to `emit()` calls
acdvorak Feb 16, 2019
c4c639d
WIP: Add TODOs
acdvorak Feb 16, 2019
8fae93f
WIP: Formatting
acdvorak Feb 16, 2019
d1fe4c4
WIP: Fix rewrite script to include exports
acdvorak Feb 18, 2019
694516c
WIP: Move `Event` interfaces to `types.ts` in mdc-chip
acdvorak Feb 18, 2019
d86e67a
WIP: Delete unused TypeScript rewrite scripts (they're now internal)
acdvorak Feb 18, 2019
31e637e
WIP: Replace `CustomEvent<T>` with custom interface to support Closur…
acdvorak Feb 19, 2019
60a75a8
WIP: Move all `Event` types to `types.ts` (except in `mdc-tabs/tab` b…
acdvorak Feb 19, 2019
c289e4b
WIP: Clean up some `strings` usages
acdvorak Feb 19, 2019
d877bc3
Merge remote-tracking branch 'origin/fix/textfield_closure_sass' into…
acdvorak Feb 19, 2019
6f9ab9f
WIP: Add missing `/index` to imports
acdvorak Feb 19, 2019
1b8e912
WIP: Fix type error
acdvorak Feb 19, 2019
08cd3bb
WIP: Add missing `./types` export to mdc-dialog
acdvorak Feb 19, 2019
1e68882
WIP: Make import paths more specific in textfield foundation
acdvorak Feb 19, 2019
03db3ea
WIP: Rename most types to include `MDC` prefix (except `RippleCapable…
acdvorak Feb 19, 2019
9406e0c
WIP: Delete unused Sass Closure rewrite script (moved internally)
acdvorak Feb 19, 2019
07bc5ea
WIP: Update `.gitignore` and `package.json` for `.rewrite-tmp`
acdvorak Feb 19, 2019
0f1a813
WIP: Style
acdvorak Feb 19, 2019
928628c
WIP: Remove unnecessary `export default MDCTabScroller`
acdvorak Feb 21, 2019
0bfcf50
WIP: Add missing `DO NOT INLINE` comment to all `getDefaultFoundation…
acdvorak Feb 21, 2019
7f6693f
WIP: Rename `RippleCapableSurface` to `MDCRippleCapableSurface`
acdvorak Feb 21, 2019
eb36503
WIP: Organize .gitignore and add comments
acdvorak Feb 21, 2019
a09f608
WIP: Re-indent all TS files to match Google style
acdvorak Feb 21, 2019
56a0650
WIP: Add missing foundation constructors and `./types` export
acdvorak Feb 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 5 additions & 99 deletions packages/mdc-animation/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2016 Google Inc.
* Copyright 2019 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,102 +21,8 @@
* THE SOFTWARE.
*/

type StandardCssPropertyName = (
'animation' | 'transform' | 'transition'
);
type PrefixedCssPropertyName = (
'-webkit-animation' | '-webkit-transform' | '-webkit-transition'
);
type StandardJsEventType = (
'animationend' | 'animationiteration' | 'animationstart' | 'transitionend'
);
type PrefixedJsEventType = (
'webkitAnimationEnd' | 'webkitAnimationIteration' | 'webkitAnimationStart' | 'webkitTransitionEnd'
);
import * as util from './util';

type CssVendorPropertyMap = { [K in StandardCssPropertyName]: CssVendorProperty };
type JsVendorPropertyMap = { [K in StandardJsEventType]: JsVendorProperty };

interface CssVendorProperty {
prefixed: PrefixedCssPropertyName;
standard: StandardCssPropertyName;
}

interface JsVendorProperty {
cssProperty: StandardCssPropertyName;
prefixed: PrefixedJsEventType;
standard: StandardJsEventType;
}

const cssPropertyNameMap: CssVendorPropertyMap = {
animation: {
prefixed: '-webkit-animation',
standard: 'animation',
},
transform: {
prefixed: '-webkit-transform',
standard: 'transform',
},
transition: {
prefixed: '-webkit-transition',
standard: 'transition',
},
};

const jsEventTypeMap: JsVendorPropertyMap = {
animationend: {
cssProperty: 'animation',
prefixed: 'webkitAnimationEnd',
standard: 'animationend',
},
animationiteration: {
cssProperty: 'animation',
prefixed: 'webkitAnimationIteration',
standard: 'animationiteration',
},
animationstart: {
cssProperty: 'animation',
prefixed: 'webkitAnimationStart',
standard: 'animationstart',
},
transitionend: {
cssProperty: 'transition',
prefixed: 'webkitTransitionEnd',
standard: 'transitionend',
},
};

function isWindow(windowObj: Window): boolean {
return Boolean(windowObj.document) && typeof windowObj.document.createElement === 'function';
}

function getCorrectPropertyName(windowObj: Window, cssProperty: StandardCssPropertyName):
StandardCssPropertyName | PrefixedCssPropertyName {
if (isWindow(windowObj) && cssProperty in cssPropertyNameMap) {
const el = windowObj.document.createElement('div');
const {standard, prefixed} = cssPropertyNameMap[cssProperty];
const isStandard = standard in el.style;
return isStandard ? standard : prefixed;
}
return cssProperty;
}

function getCorrectEventName(windowObj: Window, eventType: StandardJsEventType):
StandardJsEventType | PrefixedJsEventType {
if (isWindow(windowObj) && eventType in jsEventTypeMap) {
const el = windowObj.document.createElement('div');
const {standard, prefixed, cssProperty} = jsEventTypeMap[eventType];
const isStandard = cssProperty in el.style;
return isStandard ? standard : prefixed;
}
return eventType;
}

export {
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
PrefixedCssPropertyName,
StandardCssPropertyName,
PrefixedJsEventType,
StandardJsEventType,
getCorrectEventName,
getCorrectPropertyName,
};
export {util}; // New namespace
export * from './types';
export * from './util'; // Old namespace for backward compatibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In master, animation also exports transformStyleProperties, which seems to have disappeared from the package on the TS branch?

const transformStyleProperties = ['transform', 'WebkitTransform', 'MozTransform', 'OTransform', 'MSTransform'];

It seems very unlikely that anything external would rely on this though... (We relied on it in linear-progress but it no longer does; it uses getCorrectPropertyName now instead.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I guess that's technically a breaking change...

Should I mirror this with a PR in master to ensure it ends up in the changelog?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible and reasonable to do that in master? (I guess it comes down to being able to make a similar change to linear-progress in master.)

26 changes: 24 additions & 2 deletions typings/custom.d.ts → packages/mdc-animation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@
* THE SOFTWARE.
*/

declare interface Window {
CSS: CSS;
export type StandardCssPropertyName =
'animation' | 'transform' | 'transition';

export type PrefixedCssPropertyName =
'-webkit-animation' | '-webkit-transform' | '-webkit-transition';

export type StandardJsEventType =
'animationend' | 'animationiteration' | 'animationstart' | 'transitionend';

export type PrefixedJsEventType =
'webkitAnimationEnd' | 'webkitAnimationIteration' | 'webkitAnimationStart' | 'webkitTransitionEnd';

export interface CssVendorProperty {
prefixed: PrefixedCssPropertyName;
standard: StandardCssPropertyName;
}

export interface JsVendorProperty {
cssProperty: StandardCssPropertyName;
prefixed: PrefixedJsEventType;
standard: StandardJsEventType;
}

export type CssVendorPropertyMap = { [K in StandardCssPropertyName]: CssVendorProperty };
export type JsVendorPropertyMap = { [K in StandardJsEventType]: JsVendorProperty };
92 changes: 92 additions & 0 deletions packages/mdc-animation/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

import {
CssVendorPropertyMap, JsVendorPropertyMap,
PrefixedCssPropertyName, PrefixedJsEventType,
StandardCssPropertyName, StandardJsEventType,
} from './types';

const cssPropertyNameMap: CssVendorPropertyMap = {
animation: {
prefixed: '-webkit-animation',
standard: 'animation',
},
transform: {
prefixed: '-webkit-transform',
standard: 'transform',
},
transition: {
prefixed: '-webkit-transition',
standard: 'transition',
},
};

const jsEventTypeMap: JsVendorPropertyMap = {
animationend: {
cssProperty: 'animation',
prefixed: 'webkitAnimationEnd',
standard: 'animationend',
},
animationiteration: {
cssProperty: 'animation',
prefixed: 'webkitAnimationIteration',
standard: 'animationiteration',
},
animationstart: {
cssProperty: 'animation',
prefixed: 'webkitAnimationStart',
standard: 'animationstart',
},
transitionend: {
cssProperty: 'transition',
prefixed: 'webkitTransitionEnd',
standard: 'transitionend',
},
};

function isWindow(windowObj: Window): boolean {
return Boolean(windowObj.document) && typeof windowObj.document.createElement === 'function';
}

export function getCorrectPropertyName(windowObj: Window, cssProperty: StandardCssPropertyName):
StandardCssPropertyName | PrefixedCssPropertyName {
if (isWindow(windowObj) && cssProperty in cssPropertyNameMap) {
const el = windowObj.document.createElement('div');
const {standard, prefixed} = cssPropertyNameMap[cssProperty];
const isStandard = standard in el.style;
return isStandard ? standard : prefixed;
}
return cssProperty;
}

export function getCorrectEventName(windowObj: Window, eventType: StandardJsEventType):
StandardJsEventType | PrefixedJsEventType {
if (isWindow(windowObj) && eventType in jsEventTypeMap) {
const el = windowObj.document.createElement('div');
const {standard, prefixed, cssProperty} = jsEventTypeMap[eventType];
const isStandard = cssProperty in el.style;
return isStandard ? standard : prefixed;
}
return eventType;
}
4 changes: 4 additions & 0 deletions typings/dom.ie.d.ts → packages/mdc-base/externs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
declare interface Element {
msMatchesSelector?: (selector: string) => boolean;
}

declare interface Window {
CSS: CSS;
}
2 changes: 1 addition & 1 deletion packages/mdc-base/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2016 Google Inc.
* Copyright 2019 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading