-
Notifications
You must be signed in to change notification settings - Fork 177
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b037fab
Moved references to media out of animation package
3a9c2ec
Removed links from element-library to animations package
f400378
Merge branch 'main' into fix/12332-interdependency
a7807d0
Moved `generateVideoStrip` from media package to main story-editor pa…
d5f7873
Moved a test
228b19a
Inverted some flow in `usePasteTextContent`
0885cc7
Renamed props
368758b
Pedantry!
f42a43d
Merge branch 'main' into fix/12332-interdependency
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,17 +42,17 @@ import { getMediaSizePositionProps } from '@googleforcreators/media'; | |
|
||
const PRECISION = 1; | ||
|
||
export function getMediaBoundOffsets({ element }) { | ||
export function getElementOffsets(element) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
// Get elements box based on a given page size with proper ratio. | ||
const box = getBox(element, PAGE_WIDTH, PAGE_HEIGHT); | ||
// Calculate image offsets based off given box, focal point | ||
// Calculate media offsets based off given box, focal point | ||
const media = getMediaSizePositionProps( | ||
element.resource, | ||
box.width, | ||
box.height, | ||
element.scale, | ||
element.focalX, | ||
element.focalY | ||
element.scale ?? 1, | ||
element.focalX ?? 50, | ||
element.focalY ?? 50 | ||
); | ||
|
||
return { | ||
|
@@ -68,13 +68,19 @@ export function getMediaBoundOffsets({ element }) { | |
} | ||
|
||
function mapValues(obj, op) { | ||
return Object.entries(obj).reduce((accum, [key, val]) => { | ||
accum[key] = op(val); | ||
return accum; | ||
}, {}); | ||
return Object.fromEntries( | ||
Object.entries(obj).map(([key, val]) => [key, op(val)]) | ||
); | ||
} | ||
|
||
export function hasOffsets({ element }) { | ||
const offsets = getMediaBoundOffsets({ element }); | ||
export const DEFAULT_HAS_OFFSETS = { | ||
top: false, | ||
bottom: false, | ||
left: false, | ||
right: false, | ||
}; | ||
|
||
export function getHasElementOffsets(element) { | ||
const offsets = getElementOffsets(element); | ||
return mapValues(offsets, (offset) => Math.abs(offset) > PRECISION); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 thestory
package,StoryElementPropTypes
inelements
, 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)
There was a problem hiding this comment.
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.