Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript conversion of animation package #12702

Merged
merged 42 commits into from
Nov 29, 2022
Merged

TypeScript conversion of animation package #12702

merged 42 commits into from
Nov 29, 2022

Conversation

barklund
Copy link
Contributor

@barklund barklund commented Nov 16, 2022

Context

This was a big one 😅

The animation package is quite over-engineered and has a serious lack of DRY-ness with a lot of duplicated code, boilerplate and even logic. This is still only a partial conversion.

At this stage, I would welcome a sanity check, but I actually feel pretty good about the conversion, because I can see all the animations working in Storybook (except for background effects, see todo).

To-do

Need-to-have

  • Convert to TypeScript
  • Move various types and functions around to fix package dependencies
  • Invert the dependency between animation and elements, so elements now depend on animation
  • Update and rewrite tests to TypeScript
  • Convert various constants to enums
  • Update usage of animation constants in story editor
  • Update story editor animation playback
  • Fix initial lint issues
  • Fix conflicts caused by Fix rollup config and address warnings #12682 (should be trivial, just ignore main and use local only)
  • Fix lint errors in Storybook stories (probably just going to exclude them from tsconfig)
  • Fix test errors (actually only rather few left at this point)
  • Fix the last type discrepancy in createAnimation (requires making StoryAnimation a union type with all the properties specified for each different animation type)

Bugs in editor

  • Delay can sometimes not be changed (e.g. for Fly in)
  • Fly in does not actually fly in, only fade
  • Test all other animations

Nice-to-have

  • Re-enable Storybook stories for animations and update where necessary
  • Flatten and simplify effects
  • Flatten and simplify parts
  • Move simple parts in /parts/to /parts/simple/ and move effects to /parts/effects/. They're all only ever referenced by the functions inside /parts/index.tsx anyway (which will be split up above).
  • Split up contents of /parts/index.tsx into dedicated files, and add tests (esp. for getAnimationEffectFields)
  • Organize animations defaults in the same style throughout (probably with argument defaults everywhere)
  • Move types around inside the animation package for best possible overview
  • Add Storybook stories for background effects
  • Simplify fields logic
  • Simplify animation parts even further (push all component creation to JIT, not setup)

User-facing changes

None!

Testing Instructions

Test everything related to animations including old stories with animation, creating new stories with new animations, previewing animations in the editor, viewing animations in the output story.

Checklist

  • This PR addresses an existing issue and I have linked this PR to it in ZenHub
  • I have tested this code to the best of my abilities
  • I have verified accessibility to the best of my abilities (docs)
  • I have verified i18n and l10n (translation, right-to-left layout) to the best of my abilities
  • This code is covered by automated tests (unit, integration, and/or e2e) to verify it works as intended (docs)
  • I have added documentation where necessary
  • I have added a matching Type: XYZ label to the PR

Fixes #12207

Morten Barklund added 3 commits November 11, 2022 13:08
# Conflicts:
#	tsconfig.json
Note that the main story editor does not compile at this stage, but the animation package works in isolation and can be seen in action through Storybook: `npm run storybook`.
@barklund barklund added Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Pod: Prometheus labels Nov 16, 2022
@barklund barklund self-assigned this Nov 16, 2022
Morten Barklund added 3 commits November 16, 2022 20:23
# Conflicts:
#	packages/animation/src/components/AMPKeyframes.tsx
#	packages/animation/src/components/context.ts
#	packages/animation/src/components/provider.tsx
#	packages/animation/src/components/useStoryAnimationContext.ts
#	packages/animation/src/effects/backgroundPan/animationProps.js
#	packages/animation/src/effects/fadeIn.ts
#	packages/animation/src/effects/flyIn/animationProps.js
#	packages/animation/src/effects/pulse.ts
#	packages/animation/src/effects/zoom/animationProps.js
#	packages/animation/src/parts/defaultFields.ts
#	packages/animation/src/parts/simpleAnimation.js
#	packages/animation/src/parts/test/index.js
#	packages/animation/src/parts/types.js
#	packages/animation/src/types.js
#	packages/animation/src/types/index.ts
#	packages/animation/src/types/types.js
#	packages/elements/src/utils/index.ts
#	packages/media/src/types/mediaElement.ts
Morten Barklund added 17 commits November 17, 2022 19:22
A bunch of anim constants have been converted from object to enums and thus had their casing updating from `SCREAMING_SNAKE_CASE` to `PascalCase`.
…-stories-wp into code/12207-ts-anim

# Conflicts:
#	packages/story-editor/src/components/panels/design/animation/animation.js
Thís required creating a union type for all the animations. However, it works a little weird, so had to do a bunch of `as const` stuff in tests, so worry about typing the implementation of this in other packages, but for now this is good.
Yes, `panDirection` would be better, but it is already referenced a ton of places, so it is a lot of unnecessary work to change it.
@barklund barklund changed the title WIP: TypeScript conversion of animation package TypeScript conversion of animation package Nov 24, 2022
@barklund barklund marked this pull request as ready for review November 24, 2022 13:00
@googleforcreators-bot
Copy link
Collaborator

googleforcreators-bot commented Nov 24, 2022

Plugin builds for f864b46 are ready 🛎️!

@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2022

Size Change: -15.2 kB (-1%)

Total Size: 2.71 MB

Filename Size Change
assets/js/chunk-web-animations-js.js 0 B -14.6 kB (removed) 🏆
assets/js/wp-story-editor.js 1.43 MB -605 B (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/carousel-view-rtl.css 702 B 0 B
assets/css/carousel-view.css 701 B 0 B
assets/css/web-stories-block-rtl.css 4.54 kB 0 B
assets/css/web-stories-block.css 4.58 kB 0 B
assets/css/web-stories-embed-rtl.css 318 B 0 B
assets/css/web-stories-embed.css 317 B 0 B
assets/css/web-stories-list-styles-rtl.css 2.35 kB 0 B
assets/css/web-stories-list-styles.css 2.38 kB 0 B
assets/css/web-stories-theme-style-twentyeleven-rtl.css 102 B 0 B
assets/css/web-stories-theme-style-twentyeleven.css 102 B 0 B
assets/css/web-stories-theme-style-twentyfifteen-rtl.css 251 B 0 B
assets/css/web-stories-theme-style-twentyfifteen.css 251 B 0 B
assets/css/web-stories-theme-style-twentyfourteen-rtl.css 287 B 0 B
assets/css/web-stories-theme-style-twentyfourteen.css 287 B 0 B
assets/css/web-stories-theme-style-twentyseventeen-rtl.css 288 B 0 B
assets/css/web-stories-theme-style-twentyseventeen.css 288 B 0 B
assets/css/web-stories-theme-style-twentysixteen-rtl.css 224 B 0 B
assets/css/web-stories-theme-style-twentysixteen.css 224 B 0 B
assets/css/web-stories-theme-style-twentyten-rtl.css 143 B 0 B
assets/css/web-stories-theme-style-twentyten.css 143 B 0 B
assets/css/web-stories-theme-style-twentytwelve-rtl.css 256 B 0 B
assets/css/web-stories-theme-style-twentytwelve.css 256 B 0 B
assets/css/web-stories-theme-style-twentytwenty-rtl.css 86 B 0 B
assets/css/web-stories-theme-style-twentytwenty.css 86 B 0 B
assets/css/web-stories-theme-style-twentytwentyone-rtl.css 326 B 0 B
assets/css/web-stories-theme-style-twentytwentyone.css 326 B 0 B
assets/css/web-stories-widget-rtl.css 482 B 0 B
assets/css/web-stories-widget.css 482 B 0 B
assets/css/wp-dashboard-rtl.css 657 B 0 B
assets/css/wp-dashboard.css 659 B 0 B
assets/css/wp-story-editor-rtl.css 769 B 0 B
assets/css/wp-story-editor.css 771 B 0 B
assets/js/1047.js 37.6 kB 0 B
assets/js/2475.js 7.78 kB 0 B
assets/js/3371.js 194 kB +32 B (0%)
assets/js/4422.js 49.3 kB 0 B
assets/js/6071.js 92.9 kB 0 B
assets/js/9750.js 12.8 kB 0 B
assets/js/carousel-view.js 3.5 kB 0 B
assets/js/chunk-colorthief.js 2.64 kB 0 B
assets/js/chunk-ffmpeg.js 5.88 kB 0 B
assets/js/chunk-html-to-image.js 4.51 kB 0 B
assets/js/chunk-opentype.js 96 B 0 B
assets/js/chunk-react-calendar.js 22.7 kB 0 B
assets/js/chunk-react-color.js 44.3 kB 0 B
assets/js/chunk-selfie-segmentation.js 12.5 kB 0 B
assets/js/chunk-web-stories-template-0-metaData.js 546 B 0 B
assets/js/chunk-web-stories-template-0.js 11.4 kB 0 B
assets/js/chunk-web-stories-template-1-metaData.js 540 B 0 B
assets/js/chunk-web-stories-template-1.js 9.57 kB 0 B
assets/js/chunk-web-stories-template-10-metaData.js 532 B 0 B
assets/js/chunk-web-stories-template-10.js 7.34 kB 0 B
assets/js/chunk-web-stories-template-11-metaData.js 539 B 0 B
assets/js/chunk-web-stories-template-11.js 9.02 kB 0 B
assets/js/chunk-web-stories-template-12-metaData.js 496 B 0 B
assets/js/chunk-web-stories-template-12.js 9.66 kB 0 B
assets/js/chunk-web-stories-template-13-metaData.js 525 B 0 B
assets/js/chunk-web-stories-template-13.js 7.37 kB 0 B
assets/js/chunk-web-stories-template-14-metaData.js 582 B 0 B
assets/js/chunk-web-stories-template-14.js 7.36 kB 0 B
assets/js/chunk-web-stories-template-15-metaData.js 544 B 0 B
assets/js/chunk-web-stories-template-15.js 8.98 kB 0 B
assets/js/chunk-web-stories-template-16-metaData.js 588 B 0 B
assets/js/chunk-web-stories-template-16.js 10.8 kB 0 B
assets/js/chunk-web-stories-template-17-metaData.js 540 B 0 B
assets/js/chunk-web-stories-template-17.js 9.18 kB 0 B
assets/js/chunk-web-stories-template-18-metaData.js 587 B 0 B
assets/js/chunk-web-stories-template-18.js 9.86 kB 0 B
assets/js/chunk-web-stories-template-19-metaData.js 501 B 0 B
assets/js/chunk-web-stories-template-19.js 10.8 kB 0 B
assets/js/chunk-web-stories-template-2-metaData.js 586 B 0 B
assets/js/chunk-web-stories-template-2.js 9.25 kB 0 B
assets/js/chunk-web-stories-template-20-metaData.js 548 B 0 B
assets/js/chunk-web-stories-template-20.js 8.97 kB 0 B
assets/js/chunk-web-stories-template-21-metaData.js 536 B 0 B
assets/js/chunk-web-stories-template-21.js 9.84 kB 0 B
assets/js/chunk-web-stories-template-22-metaData.js 525 B 0 B
assets/js/chunk-web-stories-template-22.js 7.79 kB 0 B
assets/js/chunk-web-stories-template-23-metaData.js 604 B 0 B
assets/js/chunk-web-stories-template-23.js 7.43 kB 0 B
assets/js/chunk-web-stories-template-24-metaData.js 517 B 0 B
assets/js/chunk-web-stories-template-24.js 11.6 kB 0 B
assets/js/chunk-web-stories-template-25-metaData.js 543 B 0 B
assets/js/chunk-web-stories-template-25.js 7.04 kB 0 B
assets/js/chunk-web-stories-template-26-metaData.js 600 B 0 B
assets/js/chunk-web-stories-template-26.js 7.25 kB 0 B
assets/js/chunk-web-stories-template-27-metaData.js 542 B 0 B
assets/js/chunk-web-stories-template-27.js 7.78 kB 0 B
assets/js/chunk-web-stories-template-28-metaData.js 532 B 0 B
assets/js/chunk-web-stories-template-28.js 9.01 kB 0 B
assets/js/chunk-web-stories-template-29-metaData.js 561 B 0 B
assets/js/chunk-web-stories-template-29.js 9.23 kB 0 B
assets/js/chunk-web-stories-template-3-metaData.js 539 B 0 B
assets/js/chunk-web-stories-template-3.js 8.38 kB 0 B
assets/js/chunk-web-stories-template-30-metaData.js 576 B 0 B
assets/js/chunk-web-stories-template-30.js 7.87 kB 0 B
assets/js/chunk-web-stories-template-31-metaData.js 503 B 0 B
assets/js/chunk-web-stories-template-31.js 10.3 kB 0 B
assets/js/chunk-web-stories-template-32-metaData.js 552 B 0 B
assets/js/chunk-web-stories-template-32.js 13.2 kB 0 B
assets/js/chunk-web-stories-template-33-metaData.js 491 B 0 B
assets/js/chunk-web-stories-template-33.js 9.04 kB 0 B
assets/js/chunk-web-stories-template-34-metaData.js 570 B 0 B
assets/js/chunk-web-stories-template-34.js 7.55 kB 0 B
assets/js/chunk-web-stories-template-35-metaData.js 565 B 0 B
assets/js/chunk-web-stories-template-35.js 8.87 kB 0 B
assets/js/chunk-web-stories-template-36-metaData.js 575 B 0 B
assets/js/chunk-web-stories-template-36.js 12.6 kB 0 B
assets/js/chunk-web-stories-template-37-metaData.js 529 B 0 B
assets/js/chunk-web-stories-template-37.js 6.69 kB 0 B
assets/js/chunk-web-stories-template-38-metaData.js 572 B 0 B
assets/js/chunk-web-stories-template-38.js 7.89 kB 0 B
assets/js/chunk-web-stories-template-39-metaData.js 589 B 0 B
assets/js/chunk-web-stories-template-39.js 8.04 kB 0 B
assets/js/chunk-web-stories-template-4-metaData.js 564 B 0 B
assets/js/chunk-web-stories-template-4.js 12.6 kB 0 B
assets/js/chunk-web-stories-template-40-metaData.js 556 B 0 B
assets/js/chunk-web-stories-template-40.js 10.1 kB 0 B
assets/js/chunk-web-stories-template-41-metaData.js 573 B 0 B
assets/js/chunk-web-stories-template-41.js 7.72 kB 0 B
assets/js/chunk-web-stories-template-42-metaData.js 521 B 0 B
assets/js/chunk-web-stories-template-42.js 6.96 kB 0 B
assets/js/chunk-web-stories-template-43-metaData.js 557 B 0 B
assets/js/chunk-web-stories-template-43.js 8.7 kB 0 B
assets/js/chunk-web-stories-template-44-metaData.js 583 B 0 B
assets/js/chunk-web-stories-template-44.js 11 kB 0 B
assets/js/chunk-web-stories-template-45-metaData.js 565 B 0 B
assets/js/chunk-web-stories-template-45.js 7.48 kB 0 B
assets/js/chunk-web-stories-template-46-metaData.js 531 B 0 B
assets/js/chunk-web-stories-template-46.js 5.2 kB 0 B
assets/js/chunk-web-stories-template-47-metaData.js 591 B 0 B
assets/js/chunk-web-stories-template-47.js 9.37 kB 0 B
assets/js/chunk-web-stories-template-48-metaData.js 556 B 0 B
assets/js/chunk-web-stories-template-48.js 9.05 kB 0 B
assets/js/chunk-web-stories-template-49-metaData.js 518 B 0 B
assets/js/chunk-web-stories-template-49.js 9.63 kB 0 B
assets/js/chunk-web-stories-template-5-metaData.js 556 B 0 B
assets/js/chunk-web-stories-template-5.js 9.89 kB 0 B
assets/js/chunk-web-stories-template-50-metaData.js 503 B 0 B
assets/js/chunk-web-stories-template-50.js 9.09 kB 0 B
assets/js/chunk-web-stories-template-51-metaData.js 526 B 0 B
assets/js/chunk-web-stories-template-51.js 10.3 kB 0 B
assets/js/chunk-web-stories-template-52-metaData.js 601 B 0 B
assets/js/chunk-web-stories-template-52.js 10.3 kB 0 B
assets/js/chunk-web-stories-template-53-metaData.js 551 B 0 B
assets/js/chunk-web-stories-template-53.js 5.76 kB 0 B
assets/js/chunk-web-stories-template-54-metaData.js 547 B 0 B
assets/js/chunk-web-stories-template-54.js 7.63 kB 0 B
assets/js/chunk-web-stories-template-55-metaData.js 574 B 0 B
assets/js/chunk-web-stories-template-55.js 7.09 kB 0 B
assets/js/chunk-web-stories-template-56-metaData.js 542 B 0 B
assets/js/chunk-web-stories-template-56.js 9.81 kB 0 B
assets/js/chunk-web-stories-template-57-metaData.js 528 B 0 B
assets/js/chunk-web-stories-template-57.js 14.8 kB 0 B
assets/js/chunk-web-stories-template-58-metaData.js 554 B 0 B
assets/js/chunk-web-stories-template-58.js 5.71 kB 0 B
assets/js/chunk-web-stories-template-59-metaData.js 590 B 0 B
assets/js/chunk-web-stories-template-59.js 8.92 kB 0 B
assets/js/chunk-web-stories-template-6-metaData.js 568 B 0 B
assets/js/chunk-web-stories-template-6.js 7.04 kB 0 B
assets/js/chunk-web-stories-template-60-metaData.js 509 B 0 B
assets/js/chunk-web-stories-template-60.js 9.48 kB 0 B
assets/js/chunk-web-stories-template-7-metaData.js 569 B 0 B
assets/js/chunk-web-stories-template-7.js 7.43 kB 0 B
assets/js/chunk-web-stories-template-8-metaData.js 569 B 0 B
assets/js/chunk-web-stories-template-8.js 8.87 kB 0 B
assets/js/chunk-web-stories-template-9-metaData.js 580 B 0 B
assets/js/chunk-web-stories-template-9.js 8.39 kB 0 B
assets/js/chunk-web-stories-templates.js 1.17 kB 0 B
assets/js/chunk-web-stories-textset-0.js 5 kB 0 B
assets/js/chunk-web-stories-textset-1.js 6.58 kB 0 B
assets/js/chunk-web-stories-textset-2.js 7.57 kB 0 B
assets/js/chunk-web-stories-textset-3.js 14.6 kB 0 B
assets/js/chunk-web-stories-textset-4.js 4.1 kB 0 B
assets/js/chunk-web-stories-textset-5.js 5.41 kB 0 B
assets/js/chunk-web-stories-textset-6.js 5.21 kB 0 B
assets/js/chunk-web-stories-textset-7.js 10 kB 0 B
assets/js/generateBlurhash.worker.worker.js 1.1 kB 0 B
assets/js/imgareaselect.js 3.77 kB 0 B
assets/js/lightbox.js 550 B 0 B
assets/js/tinymce-button.js 2.85 kB 0 B
assets/js/web-stories-activation-notice.js 27.1 kB 0 B
assets/js/web-stories-block.js 22.7 kB +30 B (0%)
assets/js/web-stories-embed.js 20 B 0 B
assets/js/web-stories-widget.js 587 B 0 B
assets/js/wp-dashboard.js 63.2 kB 0 B

compressed-size-action

Copy link
Contributor

@miina miina left a comment

Choose a reason for hiding this comment

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

Nice refactor!

Will finish reviewing tomorrow:
Screenshot 2022-11-24 at 16 23 42

packages/media/src/types/mediaElement.ts Show resolved Hide resolved
packages/media/src/getElementOffsets.ts Outdated Show resolved Hide resolved
packages/animation/src/utils/getGlobalSpace.ts Outdated Show resolved Hide resolved
packages/animation/src/types/keyframes.ts Outdated Show resolved Hide resolved
packages/animation/src/types/effects.ts Outdated Show resolved Hide resolved
packages/animation/src/parts/simple/zoom.ts Show resolved Hide resolved
packages/animation/src/parts/getAnimationEffectFields.ts Outdated Show resolved Hide resolved
packages/animation/src/parts/types.ts Show resolved Hide resolved
@miina miina mentioned this pull request Nov 25, 2022
12 tasks
Copy link
Contributor

@miina miina left a comment

Choose a reason for hiding this comment

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

LGTM!

Doesn't seem ideal to define a similar element type in different packages but if there's no better alternative currently, then let's go with that.

@barklund barklund merged commit 7e8f703 into main Nov 29, 2022
@barklund barklund deleted the code/12207-ts-anim branch November 29, 2022 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript: Convert animation package
4 participants