Skip to content

Commit

Permalink
Fix rollup config and address warnings
Browse files Browse the repository at this point in the history
Reduces number of files using named and default exports together.

Consumers of your bundle will have to use `chunk['default’]` to access their default export, which is error prone and confusing.

Also de-dupes date-fns versions.
  • Loading branch information
swissspidy committed Nov 14, 2022
1 parent 4915741 commit 6520266
Show file tree
Hide file tree
Showing 93 changed files with 1,238 additions and 706 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"overrides": {
"@axe-core/puppeteer": {
"puppeteer": "^19.0.0"
}
},
"date-fns": "^2.29.3"
},
"scripts": {
"build": "npm-run-all build:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/activation-notice/src/app/config/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
import { createContext } from '@wordpress/element';

export const INITIAL_STATE = {};
const INITIAL_STATE = {};

export interface ContextState {
isRTL: boolean;
Expand Down
16 changes: 1 addition & 15 deletions packages/animation/src/components/AMPKeyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,7 @@ import { useMemo } from '@googleforcreators/react';
*/
import { KeyframesOutput } from '../outputs';
import useStoryAnimationContext from './useStoryAnimationContext';

export function generateKeyframesMap(targets, getAnimationParts) {
return targets.reduce((acc, target) => {
return {
...acc,
...getAnimationParts(target).reduce((a, part) => {
const { generatedKeyframes } = part;
return {
...a,
...generatedKeyframes,
};
}, acc),
};
}, {});
}
import generateKeyframesMap from './generateKeyframesMap';

function AMPKeyframes() {
const {
Expand Down
24 changes: 24 additions & 0 deletions packages/animation/src/components/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import { createContext } from '@googleforcreators/react';

const Context = createContext(null);

export default Context;
32 changes: 32 additions & 0 deletions packages/animation/src/components/generateKeyframesMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

function generateKeyframesMap(targets, getAnimationParts) {
return targets.reduce((acc, target) => {
return {
...acc,
...getAnimationParts(target).reduce((a, part) => {
const { generatedKeyframes } = part;
return {
...a,
...generatedKeyframes,
};
}, acc),
};
}, {});
}

export default generateKeyframesMap;
5 changes: 1 addition & 4 deletions packages/animation/src/components/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
useReducer,
useRef,
useState,
createContext,
} from '@googleforcreators/react';
import { clamp } from '@googleforcreators/units';
import { v4 as uuidv4 } from 'uuid';
Expand All @@ -42,8 +41,7 @@ if (!('KeyframeEffect' in window)) {
import { StoryElementPropType } from '../types';
import { AnimationPart } from '../parts';
import { AnimationProps } from '../parts/types';

const Context = createContext(null);
import Context from './context';

const WAAPIAnimationMachine = {
idle: {
Expand Down Expand Up @@ -317,4 +315,3 @@ Provider.propTypes = {
};

export default Provider;
export { Context as StoryAnimationContext };
75 changes: 0 additions & 75 deletions packages/animation/src/components/test/AMPKeyframes.js

This file was deleted.

71 changes: 71 additions & 0 deletions packages/animation/src/components/test/generateKeyframesMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import generateKeyframesMap from '../generateKeyframesMap';

const mockGetAnimationParts = (src) => (target) => src[target];
const mockAnimationPart = (keyframes) => ({ generatedKeyframes: keyframes });

describe('generateKeyframesMap', () => {
it('should flatten keyframes into a single map', () => {
const targets = ['target1', 'target2', 'target3'];
const parts = {
[targets[0]]: [
mockAnimationPart({ bounce: { transform: [1, 3, 4] } }),
mockAnimationPart({ dance: { transform: [5, 7, 9] } }),
],
[targets[1]]: [mockAnimationPart({ flip: { transform: [2, 5, 8] } })],
[targets[2]]: [mockAnimationPart({ blinkOn: { opacity: [0, 1, 0, 1] } })],
};

const getAnimationParts = mockGetAnimationParts(parts);

expect(generateKeyframesMap(targets, getAnimationParts)).toStrictEqual({
bounce: { transform: [1, 3, 4] },
dance: { transform: [5, 7, 9] },
flip: { transform: [2, 5, 8] },
blinkOn: { opacity: [0, 1, 0, 1] },
});
});

it('should consolidate duplicate keyframes', () => {
const bounceKeyframes = { bounce: { transform: [1, 3, 4] } };

const targets = ['target1', 'target2', 'target3'];
const parts = {
[targets[0]]: [
mockAnimationPart(bounceKeyframes),
mockAnimationPart({ dance: { transform: [5, 7, 9] } }),
],
[targets[1]]: [mockAnimationPart(bounceKeyframes)],
[targets[2]]: [
mockAnimationPart(bounceKeyframes),
mockAnimationPart({ blinkOn: { opacity: [0, 1, 0, 1] } }),
],
};

const getAnimationParts = mockGetAnimationParts(parts);

expect(generateKeyframesMap(targets, getAnimationParts)).toStrictEqual({
bounce: { transform: [1, 3, 4] },
dance: { transform: [5, 7, 9] },
blinkOn: { opacity: [0, 1, 0, 1] },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import { identity, useContextSelector } from '@googleforcreators/react';

/**
* Internal dependencies
*/
import { StoryAnimationContext } from './provider';
import StoryAnimationContext from './context';

function useStoryAnimationContext(selector) {
return useContextSelector(StoryAnimationContext, selector ?? identity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import { __, _x } from '@googleforcreators/i18n';

/**
* Internal dependencies
*/
import { FIELD_TYPES, DIRECTION } from '../../constants';
import { AnimationInputPropTypes } from '../types';

export const PanEffectInputPropTypes = {
panDir: PropTypes.shape(AnimationInputPropTypes),
duration: PropTypes.shape(AnimationInputPropTypes),
};

export default {
panDir: {
Expand Down
30 changes: 30 additions & 0 deletions packages/animation/src/effects/backgroundPan/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/
import { AnimationInputPropTypes } from '../types';

export const PanEffectInputPropTypes = {
panDir: PropTypes.shape(AnimationInputPropTypes),
duration: PropTypes.shape(AnimationInputPropTypes),
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@
* limitations under the License.
*/

/**
* Internal dependencies
*/
export {
default,
PanEffectInputPropTypes as PanAndZoomEffectInputPropTypes,
} from '../backgroundPan/animationProps';
export { default } from '../backgroundPan/animationProps';
17 changes: 17 additions & 0 deletions packages/animation/src/effects/backgroundPanAndZoom/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export { PanEffectInputPropTypes as PanAndZoomEffectInputPropTypes } from '../backgroundPan/types';

0 comments on commit 6520266

Please sign in to comment.