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

Reworking the elements package #12557

Merged
merged 26 commits into from Nov 11, 2022
Merged

Reworking the elements package #12557

merged 26 commits into from Nov 11, 2022

Conversation

barklund
Copy link
Contributor

@barklund barklund commented Oct 28, 2022

Context

More work on the elements package, as well as deprecating the types package completely.

(this is slightly WIP - the git merge was a bit muddy to get an overview of, so might make additional changes after creating this PR)

User-facing changes

None (I hope!)

Testing Instructions

  • Full (single-browser) smoke-test is probably a good idea, as this touches on a lot of things through the entire application.

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

Morten Barklund added 5 commits October 12, 2022 22:14
# Conflicts:
#	package-lock.json
#	packages/elements/src/elementType.js
#	packages/elements/src/elementType.ts
#	packages/elements/src/types.js
#	packages/elements/src/types.ts
#	packages/elements/src/types/element.ts
#	packages/elements/src/types/page.ts
#	packages/elements/src/types/propTypes.ts
#	packages/elements/src/utils/createNewElement.ts
#	packages/elements/src/utils/createPage.ts
#	packages/elements/src/utils/duplicateElement.ts
#	packages/elements/src/utils/duplicatePage.ts
#	packages/elements/src/utils/getElementOffsets.ts
#	packages/elements/src/utils/getElementOrigin.ts
#	packages/elements/src/utils/getLayerName.ts
#	packages/elements/src/utils/getTransformFlip.ts
#	packages/elements/src/utils/isElementBelowLimit.ts
#	packages/elements/tsconfig.json
#	packages/migration/package.json
#	packages/templates/src/raw/a-day-in-the-life/index.ts
#	packages/units/src/context.ts
#	packages/units/src/dimensions.ts
#	packages/units/src/getBoundRect.ts
#	packages/units/src/types.ts
#	tsconfig.json
@barklund barklund added Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Pod: Prometheus labels Oct 28, 2022
@barklund barklund requested review from miina and merapi October 28, 2022 12:48
@barklund barklund self-assigned this Oct 28, 2022
@barklund barklund removed the request for review from spacedmonkey October 28, 2022 12:54
@spacedmonkey
Copy link
Contributor

This PR should be renamed removing the types package.

Copy link
Collaborator

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

An additional note:

We have separate elements and element-library packages for a reason, so that these are decoupled.

We should not put type definitions for individual element types back into elements package when we have this dedicated package.

packages/elements/src/utils/getElementOrigin.ts Outdated Show resolved Hide resolved
packages/elements/tsconfig.json Outdated Show resolved Hide resolved
packages/elements/src/utils/isElementBelowLimit.ts Outdated Show resolved Hide resolved
packages/media/src/types/resource.ts Outdated Show resolved Hide resolved
packages/media/src/types/resource.ts Outdated Show resolved Hide resolved
packages/media/src/types/resource.ts Outdated Show resolved Hide resolved
packages/media/src/types/resource.ts Outdated Show resolved Hide resolved
packages/media/src/types/resource.ts Show resolved Hide resolved
packages/media/src/types/resourceInput.ts Outdated Show resolved Hide resolved
@barklund
Copy link
Contributor Author

We have separate elements and element-library packages for a reason, so that these are decoupled.

We should not put type definitions for individual element types back into elements package when we have this dedicated package.

Yeah, that's why I wanted to convert both packages to put these in the element library, but that's turned out to be too much work (a lot of the components are tricky), so the element types are just here in the elements package until we get to the element library package. With the element library already depending on the elements package, I didn't think this was a big problem.

I we can put them in the element library right away without converting the rest of that package, I'm all for it, but didn't know the right way to do that.

@googleforcreators-bot
Copy link
Collaborator

googleforcreators-bot commented Oct 31, 2022

Plugin builds for f1e7468 are ready 🛎️!

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2022

Size Change: +39 B (0%)

Total Size: 2.72 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.51 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.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/2475.js 7.78 kB 0 B
assets/js/3371.js 194 kB 0 B
assets/js/4422.js 49.3 kB 0 B
assets/js/6071.js 92.9 kB 0 B
assets/js/9162.js 36.5 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 12.5 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-animations-js.js 14.6 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.6 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.36 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.07 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.68 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.39 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.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.2 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.9 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.29 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.99 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.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 604 B 0 B
assets/js/chunk-web-stories-template-23.js 7.47 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.7 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.06 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.26 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.8 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.05 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.24 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.39 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.88 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.3 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.06 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.57 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.9 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.7 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.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.92 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.07 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 556 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 573 B 0 B
assets/js/chunk-web-stories-template-41.js 7.74 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.99 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.75 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.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.5 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.21 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.41 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.08 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.91 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.13 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.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.66 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.12 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.85 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.9 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.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.95 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.05 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.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.45 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.9 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.45 kB 0 B
assets/js/chunk-web-stories-templates.js 1.17 kB 0 B
assets/js/chunk-web-stories-textset-0.js 5.04 kB 0 B
assets/js/chunk-web-stories-textset-1.js 6.63 kB 0 B
assets/js/chunk-web-stories-textset-2.js 7.62 kB 0 B
assets/js/chunk-web-stories-textset-3.js 15 kB 0 B
assets/js/chunk-web-stories-textset-4.js 4.14 kB 0 B
assets/js/chunk-web-stories-textset-5.js 5.45 kB 0 B
assets/js/chunk-web-stories-textset-6.js 5.25 kB 0 B
assets/js/chunk-web-stories-textset-7.js 10.1 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 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 64.2 kB 0 B
assets/js/wp-story-editor.js 1.44 MB +39 B (0%)

compressed-size-action

@swissspidy
Copy link
Collaborator

I we can put them in the element library right away without converting the rest of that package, I'm all for it, but didn't know the right way to do that.

In tsconfig.json you can adjust "include" to something like "include": ["src/types.ts"] / "include": ["src/types/**/*"] so that only this one file/folder is checked by the compiler, and nothing else.

Here's an example:

https://github.com/GoogleForCreators/web-stories-wp/tree/try/element-library-types

This works well, the only problems are packages/masks/src/borderedMaskedElement.tsx referencing ShapeElement and the templates package referencing all element types (TemplatePage using UnionElement[] / packages/templates/src/getTemplates.ts modifying element.resource.src

Since these packages shouldn't really rely on element-library just for types, we need to find a better solution there.

For masks it probably means referencing BackgroundableElement / DefaultBackgroundElement instead of ShapeElement

For packages/templates/src/getTemplates.ts maybe means simply ignoring TS errors?

@barklund
Copy link
Contributor Author

barklund commented Nov 1, 2022

I we can put them in the element library right away without converting the rest of that package, I'm all for it, but didn't know the right way to do that.

In tsconfig.json you can adjust "include" to something like "include": ["src/types.ts"] / "include": ["src/types/**/*"] so that only this one file/folder is checked by the compiler, and nothing else.

Here's an example:

https://github.com/GoogleForCreators/web-stories-wp/tree/try/element-library-types

This works well, the only problems are packages/masks/src/borderedMaskedElement.tsx referencing ShapeElement and the templates package referencing all element types (TemplatePage using UnionElement[] / packages/templates/src/getTemplates.ts modifying element.resource.src

Since these packages shouldn't really rely on element-library just for types, we need to find a better solution there.

For masks it probably means referencing BackgroundableElement / DefaultBackgroundElement instead of ShapeElement

For packages/templates/src/getTemplates.ts maybe means simply ignoring TS errors?

Thanks, I'll work through these and see if I can find a good solution!

@barklund
Copy link
Contributor Author

barklund commented Nov 1, 2022

I we can put them in the element library right away without converting the rest of that package, I'm all for it, but didn't know the right way to do that.

This works well, the only problems are packages/masks/src/borderedMaskedElement.tsx referencing ShapeElement and the templates package referencing all element types (TemplatePage using UnionElement[] / packages/templates/src/getTemplates.ts modifying element.resource.src

Thanks, I'll work through these and see if I can find a good solution!

We already had the BackgroundableElement for what masks wanted, and for template, MediaElement and SequenceResource (a resource with a poster) combined seems to fix the day.

Thanks for the hints!

@@ -40,6 +46,8 @@ export interface Mask {
name?: string;
path?: string;
ratio?: number;
iconPath?: string;
iconRatio?: number;
supportsBorder?: boolean;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering: should the Mask type better live in the masks package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The masks package depends on the elements package, and that dependency is pretty locked-in. There are all the components for display, frame, and output, that have element typings as well as several util functions (shouldDisplayBorder, canMaskHaveBorder, ...). And the big one is the BorderedMaskedElement using many element features.

Some of these could be solved by utilizing DimensionableElement from units package (though the border in that package does not include a color which masks need, which would add a dependency on the patterns package, but that's probably okay), others could be solved by also adding a MaskableElement to the masks package, but we still also need things like the flip and isBackground properties from the elements (in the BorderedMaskedElement), so that would require making even more element interfaces.

It's doable, but it's getting a bit complex (a naming is getting terrible 😂). Let's move this idea to a new ticket.

isMedia?: boolean;
getLayerText: (element: E) => string;
defaultAttributes: Partial<E>;
Edit: React.FC<EditProps<E>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen in multiple articles / resources mentioned that React.FC is better not to use, e.g. because it causes the component to implicitly accept children. I think there were some other reasons as well. Thoughts? You probably have more information about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That has been changed in React 18. React.FC (or React.FunctionComponent) no longer implicitly accepts children.

BUT we're not using React 18, and probably never will because of all the migration issues. So you're right, it should probably be changed to a more clean type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

React.VoidFunctionComponent seems to be the way to do it pre-18. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1e3577e.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Should we add the eslint configuration as well to prefer this to React.FC mentioned in the comment you shared? cc @swissspidy

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, why not, perhaps in a new PR?

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 rework! The JS tests are failing, otherwise LGTM 🐘

Morten Barklund added 5 commits November 2, 2022 15:37
Also fixed a test.

Note that there are many more instance of type:"page" in the code, but most are related to tests that will probably still work fine or templates, which will also work fine with an extra unused property. Should we add a migration though?
@barklund
Copy link
Contributor Author

barklund commented Nov 2, 2022

I think all the remaining errors come from the fact, that htmlToImage.toCanvas never resolves (neither successfully or with an error). I've tried all sorts of things, but as far as I can tell, it just halts there.

@merapi, do you have any idea how that can be? I really don't get it? It's probably something obvious, like a missing property on some element that has to be there, but why doesn't it throw an error then? Why just nothing?

@swissspidy
Copy link
Collaborator

Made that same observation here:

#12513 (comment)

@barklund
Copy link
Contributor Author

barklund commented Nov 7, 2022

There's a new issue in the config providers, because they somehow can't depend on the element library, but I actually also don't think they should.

We can move the font definitions to the elements package, that seems like a decent place for it. The product type returned by the getProducts API method really shouldn't be the product element type (which has coordinates, layer info and other stuff, not at all relevant for a "generic" product).

Where should the new non-element product interface live though? Also in elements? We need it in both the dashboard and and the story-editor packages.

Thoughts, @miina, @swissspidy?

@swissspidy
Copy link
Collaborator

The product type returned by the getProducts API method really shouldn't be the product element type

Yeah that sounds wrong, it should return a „ProductData“ type or something.

Where should the new non-element product interface live though? Also in elements? We need it in both the dashboard and and the story-editor packages.

I don‘t think dashboard does anything with product data (except for testing that the API endpoint works, for which we don‘t really need types).

Since ProductData is used by both the editor and the product element type, moving to elements might be easiest for now. In the future it could even be its own package though

Morten Barklund added 2 commits November 10, 2022 14:55
# Conflicts:
#	packages/media/src/createResource.ts
#	packages/media/src/types/propTypes.ts
#	packages/wp-story-editor/src/api/utils/normalizeResourceSizes.js
@kkalarickal
Copy link

@barklund - I spent some time smoke testing the 12557 branch on stories-qa server and basic sanity is maintained. I have some more scenarios to cover which I will do in the morning.

Basically, in a single browser instance, I went through the following:

  • Organizing web stories via Dashboard/Categories/Tags
  • Managing web stories Settings
  • Authoring/editing web stories via the stories editor
    --Insert various elements (images, videos, stickers, shapes, products, background audio, closed captions)
    -- Manipulate the element style (fonts, colors, orientation, borders, filters, background audio, closed captions, accessibility, record video/audio, manipulate video, animations)
    -- Working with Preset/Saved styles and templates
  • Draft/Preview/Publish/UnPublish pathways, with autosave and backup of half baked stories
  • Grid view, Preview, amp verification, poster image, publisher logo

The functionality follows whatever the behavior is on master-branch. There were a bunch of console errors that I wanted to share with you:

  • when opening the editor
    image.png

  • when embedding story into a WP Postimage.png

@barklund
Copy link
Contributor Author

The functionality follows whatever the behavior is on master-branch.

Good to hear.

There were a bunch of console errors that I wanted to share with you:

Hmm, that's weird. I'll check if it means anything.

@barklund
Copy link
Contributor Author

There were a bunch of console errors that I wanted to share with you:

Hmm, that's weird. I'll check if it means anything.

I'm pretty sure they're unrelated (comes from other plugins). Let's proceed.

@barklund barklund merged commit 859d9cc into main Nov 11, 2022
@barklund barklund deleted the code/12126-ts-elements branch November 11, 2022 10:05
@barklund
Copy link
Contributor Author

@kkalarickal, merging this to unblock a number of other issues. If you do end up finding something, please alert me and I'll fix it asap!

swissspidy pushed a commit that referenced this pull request Nov 17, 2022
* Moved types around and converted elements package

* WIP: convert element-library package

* Re-moved types to relevant packages and untyped the element-library

* Updating package.json

* Feedback improvements

* Fixed more from PR feedback

* Fix lint error

* Moved element definitions to element library package and updated dependencies

* Fixed React-17 React.FC issue and resource id reference

* Removed Page.type property as it is redundant

Also fixed a test.

Note that there are many more instance of type:"page" in the code, but most are related to tests that will probably still work fine or templates, which will also work fine with an extra unused property. Should we add a migration though?

* Fix imports of background audio prop type

* Fixed a karma test

* Finally fixed that annoying bg-shape-element copy thingy

* Added a comment to make sense of it

* Fix eyedropper

* Target correct element

* Updated type references for config providers

* Missing types in package.json?

* Reorganized data types to elements package

Co-authored-by: Marcin Pietruszka <marcin@webskill.pl>
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 elements package
7 participants