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

Code: Improved codebase by minimizing package interdependency #12344

Merged
merged 9 commits into from
Sep 27, 2022

Conversation

barklund
Copy link
Contributor

Context

This moves some code and/or responsibility from one package to another in four areas:

  • remove the link from animation package to media (by going through getDefinitionForType instead, which would instead add a link to the elements package in getMediaBounds function)
  • remove the link from media to element (by moving generateVideoStrip to the story-editor package)
  • remove the link from element-library to animation package (by passing the relevant BG_SCALE_* properties to MediaEdit from the story editor)
  • remove the link from rich-text package to element library package (by passing a "simpler" callback (content: string) => void to usePasteTextContent)

Testing Instructions

To make sure no regressions are introduced, please thoroughly test these bits of functionality:

Video strip

  1. Add a local video to a page
  2. Click the scissor icon in the design mode to enter trim mode
  3. Observe that the video strip is correctly generated

Media pan animation

  1. Add a landscape image as background element on a page
  2. Open the animation dropdown
  3. Verify that the element animation can be set to pan left and right, but not up and down
  4. Double-click the image and scale it up a bit
  5. Open the animation dropdown
  6. Verify that the element animation can be set to pan in all directions

Media scale

  1. Add an image or video to a page
  2. Double click the element and verify that the element can be scaled between 100% to 400%.

Paste text

  1. Select some text anywhere on you computer and copy it (the raw text, not a file or anything)
  2. Click anywhere outside the canvas in the editor and make sure nothing is selected
  3. Paste using either keyboard shortcut or browser edit menu
  4. Observe that the copied text is inserted correctly as a new text element with default style

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 #12332

@barklund barklund added Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Pod: Prometheus labels Sep 21, 2022
@barklund barklund self-assigned this Sep 21, 2022
Comment on lines +65 to +67
// Temporary solution for animations. Better would be to move this
// prop type to the types package, but really?
animations: PropTypes.arrayOf(PropTypes.object),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As noted, this isn't great, but okay until we convert this package to TypeScript.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Better would be to move this prop type to the types package

Is this referring to just the animation prop type? Or all of StoryPropTypes in general?

Technically it would make sense for all of the StoryPropTypes.* prop types to live next to their respective TS counterparts, e.g. StoryPropTypes.page in the story package, StoryElementPropTypes in elements, and so on.

But yeah I guess with the conversion to TypeScript the prop types usage will slowly fade away anyway (unless we see a lot of value in keeping it around)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just this single prop type, because the dependency between the animation and the elements package have been reversed. Yes, it would make sense to move them all to the types package, I'll look at that in #12126.

@@ -42,17 +42,17 @@ import { getMediaSizePositionProps } from '@googleforcreators/media';

const PRECISION = 1;

export function getMediaBoundOffsets({ element }) {
export function getElementOffsets(element) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I know that this function only makes sense for media elements (that have scale and focal values), but I've made it general anyway (just returning all zeros for non-media).

Comment on lines +205 to +208
const hasOffset = isMedia
? getHasElementOffsets(selectedElement)
: DEFAULT_HAS_OFFSETS;
const normalizedScale = progress(selectedElement.scale || 0, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really sure if the isMedia guard is even needed here. The function will work on background shapes just fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Feels like leaving it helps better understand the intent here

@github-actions
Copy link
Contributor

github-actions bot commented Sep 21, 2022

Size Change: -59 B (0%)

Total Size: 2.71 MB

ℹ️ 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.52 kB 0 B
assets/css/web-stories-block.css 4.56 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.36 kB 0 B
assets/css/web-stories-list-styles.css 2.39 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 737 B 0 B
assets/css/wp-story-editor.css 738 B 0 B
assets/js/1814.js 7.48 kB 0 B
assets/js/4422.js 49.3 kB 0 B
assets/js/5369.js 90.4 kB 0 B
assets/js/5918.js 34.7 kB 0 B
assets/js/81.js 203 kB 0 B
assets/js/9750.js 12.8 kB 0 B
assets/js/carousel-view.js 3.41 kB 0 B
assets/js/chunk-colorthief.js 2.64 kB 0 B
assets/js/chunk-ffmpeg.js 5.89 kB 0 B
assets/js/chunk-focus-visible.js 1.01 kB 0 B
assets/js/chunk-html-to-image.js 4.5 kB 0 B
assets/js/chunk-opentype.js 96 B 0 B
assets/js/chunk-react-calendar.js 12.5 kB 0 B
assets/js/chunk-react-color.js 44.3 kB 0 B
assets/js/chunk-web-animations-js.js 14.6 kB 0 B
assets/js/chunk-web-stories-template-0-metaData.js 545 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 539 B 0 B
assets/js/chunk-web-stories-template-1.js 9.61 kB 0 B
assets/js/chunk-web-stories-template-10-metaData.js 533 B 0 B
assets/js/chunk-web-stories-template-10.js 7.37 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.09 kB 0 B
assets/js/chunk-web-stories-template-12-metaData.js 497 B 0 B
assets/js/chunk-web-stories-template-12.js 9.7 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.4 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.37 kB 0 B
assets/js/chunk-web-stories-template-15-metaData.js 544 B 0 B
assets/js/chunk-web-stories-template-15.js 9 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.9 kB 0 B
assets/js/chunk-web-stories-template-17-metaData.js 539 B 0 B
assets/js/chunk-web-stories-template-17.js 9.2 kB 0 B
assets/js/chunk-web-stories-template-18-metaData.js 585 B 0 B
assets/js/chunk-web-stories-template-18.js 9.91 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.3 kB 0 B
assets/js/chunk-web-stories-template-20-metaData.js 548 B 0 B
assets/js/chunk-web-stories-template-20.js 9.01 kB 0 B
assets/js/chunk-web-stories-template-21-metaData.js 535 B 0 B
assets/js/chunk-web-stories-template-21.js 9.85 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.83 kB 0 B
assets/js/chunk-web-stories-template-23-metaData.js 605 B 0 B
assets/js/chunk-web-stories-template-23.js 7.48 kB 0 B
assets/js/chunk-web-stories-template-24-metaData.js 516 B 0 B
assets/js/chunk-web-stories-template-24.js 11.7 kB 0 B
assets/js/chunk-web-stories-template-25-metaData.js 544 B 0 B
assets/js/chunk-web-stories-template-25.js 7.06 kB 0 B
assets/js/chunk-web-stories-template-26-metaData.js 601 B 0 B
assets/js/chunk-web-stories-template-26.js 7.27 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.82 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.07 kB 0 B
assets/js/chunk-web-stories-template-29-metaData.js 562 B 0 B
assets/js/chunk-web-stories-template-29.js 9.25 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.42 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.89 kB 0 B
assets/js/chunk-web-stories-template-31-metaData.js 502 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.3 kB 0 B
assets/js/chunk-web-stories-template-33-metaData.js 492 B 0 B
assets/js/chunk-web-stories-template-33.js 9.07 kB 0 B
assets/js/chunk-web-stories-template-34-metaData.js 571 B 0 B
assets/js/chunk-web-stories-template-34.js 7.58 kB 0 B
assets/js/chunk-web-stories-template-35-metaData.js 566 B 0 B
assets/js/chunk-web-stories-template-35.js 8.91 kB 0 B
assets/js/chunk-web-stories-template-36-metaData.js 577 B 0 B
assets/js/chunk-web-stories-template-36.js 12.7 kB 0 B
assets/js/chunk-web-stories-template-37-metaData.js 528 B 0 B
assets/js/chunk-web-stories-template-37.js 6.71 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.94 kB 0 B
assets/js/chunk-web-stories-template-39-metaData.js 588 B 0 B
assets/js/chunk-web-stories-template-39.js 8.08 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.7 kB 0 B
assets/js/chunk-web-stories-template-40-metaData.js 557 B 0 B
assets/js/chunk-web-stories-template-40.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-41-metaData.js 572 B 0 B
assets/js/chunk-web-stories-template-41.js 7.75 kB 0 B
assets/js/chunk-web-stories-template-42-metaData.js 521 B 0 B
assets/js/chunk-web-stories-template-42.js 7 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.76 kB 0 B
assets/js/chunk-web-stories-template-44-metaData.js 584 B 0 B
assets/js/chunk-web-stories-template-44.js 11.1 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.52 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.22 kB 0 B
assets/js/chunk-web-stories-template-47-metaData.js 592 B 0 B
assets/js/chunk-web-stories-template-47.js 9.42 kB 0 B
assets/js/chunk-web-stories-template-48-metaData.js 555 B 0 B
assets/js/chunk-web-stories-template-48.js 9.09 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.69 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.94 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.15 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.4 kB 0 B
assets/js/chunk-web-stories-template-52-metaData.js 602 B 0 B
assets/js/chunk-web-stories-template-52.js 10.4 kB 0 B
assets/js/chunk-web-stories-template-53-metaData.js 553 B 0 B
assets/js/chunk-web-stories-template-53.js 5.78 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.67 kB 0 B
assets/js/chunk-web-stories-template-55-metaData.js 573 B 0 B
assets/js/chunk-web-stories-template-55.js 7.13 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.87 kB 0 B
assets/js/chunk-web-stories-template-57-metaData.js 527 B 0 B
assets/js/chunk-web-stories-template-57.js 14.9 kB 0 B
assets/js/chunk-web-stories-template-58-metaData.js 555 B 0 B
assets/js/chunk-web-stories-template-58.js 5.74 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.96 kB 0 B
assets/js/chunk-web-stories-template-6-metaData.js 569 B 0 B
assets/js/chunk-web-stories-template-6.js 7.07 kB 0 B
assets/js/chunk-web-stories-template-60-metaData.js 510 B 0 B
assets/js/chunk-web-stories-template-60.js 9.51 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.46 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.93 kB 0 B
assets/js/chunk-web-stories-template-9-metaData.js 581 B 0 B
assets/js/chunk-web-stories-template-9.js 8.46 kB 0 B
assets/js/chunk-web-stories-templates.js 1.17 kB 0 B
assets/js/chunk-web-stories-textset-0.js 5.06 kB 0 B
assets/js/chunk-web-stories-textset-1.js 6.65 kB 0 B
assets/js/chunk-web-stories-textset-2.js 7.65 kB 0 B
assets/js/chunk-web-stories-textset-3.js 15.1 kB 0 B
assets/js/chunk-web-stories-textset-4.js 4.15 kB 0 B
assets/js/chunk-web-stories-textset-5.js 5.47 kB 0 B
assets/js/chunk-web-stories-textset-6.js 5.28 kB 0 B
assets/js/chunk-web-stories-textset-7.js 10.2 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.6 kB 0 B
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.7 kB 0 B
assets/js/wp-story-editor.js 1.44 MB -59 B (0%)

compressed-size-action

@googleforcreators-bot
Copy link
Collaborator

googleforcreators-bot commented Sep 21, 2022

Plugin builds for f42a43d are ready 🛎️!

Copy link
Contributor

@merapi merapi left a comment

Choose a reason for hiding this comment

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

LG, I saw no regressions.

@kkalarickal
Copy link

Thank you for the detailed areas that need testing @barklund .

Video strip generation

Test web-story: https://stories-qa-wordpress-amp.pantheonsite.io/wp-admin/post.php?post=19878&action=edit#page=%25225f845a7e-3e7b-4d18-8d75-2d6fb062f67a%2522

Confirmed that for videos that have enough frame information, it is possible to hit the :scissors icon and trim the video. It is also possible to re-trim back from the original source on subsequent attempts.

image.png

Test case permutations:

  • different formats of video
  • uploaded, recorded, linked source of videos
  • video from 3rd party media tab
  • adding video as an element, background, within another shape
  • animation + video that is trimmed
  • video with non-default style (mirrored, borders, turned, tinted, etc)

Negative test cases:

  • uploading videos with error
  • reloading the editor while trimming
  • testing on multiple browsers/os (Safari, Opera, Edge, Firefox)

@kkalarickal
Copy link

Paste text

Confirmed that copying text from another source and pasting into the canvas creates a text element that has default font/styling : left justified, Roboto font, Regulat Size 18 with 1.2 line spacing black & white.

Test Case Variations:

  • Tried with arabic (right-to-left) and other international characters (accepts and symbols) in the copied text.
  • Copy and paste text that was added to the canvas once again
  • Copy & paste into an existing text element

@kkalarickal
Copy link

Media scale

Confirmed scaling for images and video elements from 100% to 400%

Test Web Story: https://stories-qa-wordpress-amp.pantheonsite.io/wp-admin/post.php?post=19942&action=edit#page=%2522ee551669-8fb8-4983-8fc6-a5d6836ba7f7%2522

Test Case Variations:

  • tried with different image formats
  • tried with different video formats
  • tried adding media into a boundin shape
  • tried with multiple styles applied to the media asset

@kkalarickal
Copy link

Media Pan Animation

Confirmed that without scaling that the image is too small to allow PAN up or down. But side PAN left and right are supported.

image.png

Confirmed that after scaling up from 100%, immediately the PAN up and down are available depending on how the scaling was done.

image.png

Test Case Permutations:

  • tried image and video as background media
  • confirmed that other animations are also working
  • verified with different media file formats

@kkalarickal
Copy link

@barklund -- here is the set of inconsistencies that I wanted to bring to your attention:

Video strip generation

  1. the trimming did not work when I tried it on Opera/Windows10
    image.png

Paste text
2. I copied and pasted text from within the web story which had a different font/styling. However, the pasted text was still the default. As an editor, I was expecting the fonts/styles to carry over from the text that was cut from within the story itself (not external).

Media Pan Animation
3. I got an error while trying the following test scenario:

  • set an image as background
  • without changing scale set the animation to PAN left
  • in the LHS animations settings you will see the duration/delay values and four arrows. The left arrow will be highlighted and the right arrow is not. The top and bottom arrows are not clickable
  • now click the right arrow

Issue: The animation becomes None and there is a console error image.png

Expected: I was expecting the PAN left to become PAN right when I clicked the right arrow. Instead I get a console error and the animation is removed.

  1. Another issue with Media Pan Animate is the following scenarion:
  • insert a media asset and scale it
  • now you can set the PAN up or down
  • the LHS settings will show duration/delay and the arrow heads highlighted appropriately
  • now unscale the asset
  • Issue is that the animation still shows PAN down/up even though the arrows are greyed out. This can be confusing

image.png

@barklund
Copy link
Contributor Author

barklund commented Sep 27, 2022

@barklund -- here is the set of inconsistencies that I wanted to bring to your attention:

Thanks @kkalarickal for the thorough report. All of the 4 highlighted issues also occur on main, so these are not regressions (though still bugs). I will file them independently as such and merge this PR.

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.

Reduce package interdependency
5 participants