Repository navigation
Block editor: Convert utility modules to TypeScript #79323
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f31e759
Block editor: rename utils files to .ts
manzoorwanijk 312f8da
Block editor: keep use-notify-copy as .js due to store import
manzoorwanijk 6b86a2b
Block editor: convert simple utils to TypeScript
manzoorwanijk be18659
Block editor: convert medium utils to TypeScript
manzoorwanijk a8627e6
Block editor: convert dom, fit-text, and pasting utils to TypeScript
manzoorwanijk ca270a4
Block editor: convert transform-styles util to TypeScript
manzoorwanijk 636c91d
Convert color-values to TypeScript
manzoorwanijk eb4fa9a
Block editor: replace misleading numeric casts in sorting comparator
manzoorwanijk 4ff9974
Block editor: use type guard and early return in block-bindings
manzoorwanijk 90e8c24
Block editor: widen font formatter params for object passthrough
manzoorwanijk 7feb4eb
Block editor: allow nullish input in setImmutably type
manzoorwanijk 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| type Binding = { source?: string }; | ||
| type Bindings = Record< string, Binding >; | ||
|
|
||
| const DEFAULT_ATTRIBUTE = '__default'; | ||
| const PATTERN_OVERRIDES_SOURCE = 'core/pattern-overrides'; | ||
|
|
||
| /** | ||
| * Checks if the block has the `__default` binding for pattern overrides. | ||
| * | ||
| * @param bindings A block's bindings from the metadata attribute. | ||
| * | ||
| * @return Whether the block has the `__default` binding for pattern overrides. | ||
| */ | ||
| export function hasPatternOverridesDefaultBinding( | ||
| bindings: Bindings | undefined | null | ||
| ): bindings is Bindings { | ||
| return bindings?.[ DEFAULT_ATTRIBUTE ]?.source === PATTERN_OVERRIDES_SOURCE; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the bindings with the `__default` binding for pattern overrides | ||
| * replaced with the full-set of supported attributes. e.g.: | ||
| * | ||
| * - bindings passed in: `{ __default: { source: 'core/pattern-overrides' } }` | ||
| * - bindings returned: `{ content: { source: 'core/pattern-overrides' } }` | ||
| * | ||
| * @param bindings A block's bindings from the metadata attribute. | ||
| * @param supportedAttributes The block's attributes which are supported by block bindings. | ||
| * | ||
| * @return The bindings with default replaced for pattern overrides. | ||
| */ | ||
| export function replacePatternOverridesDefaultBinding( | ||
| bindings: Bindings | undefined | null, | ||
| supportedAttributes: string[] | ||
| ) { | ||
| // The `__default` binding currently only works for pattern overrides. | ||
| if ( ! hasPatternOverridesDefaultBinding( bindings ) ) { | ||
| return bindings; | ||
| } | ||
|
|
||
| const bindingsWithDefaults: Bindings = {}; | ||
| for ( const attributeName of supportedAttributes ) { | ||
| // If the block has mixed binding sources, retain any non pattern override bindings. | ||
| const bindingSource = bindings[ attributeName ] | ||
| ? bindings[ attributeName ] | ||
| : { source: PATTERN_OVERRIDES_SOURCE }; | ||
| bindingsWithDefaults[ attributeName ] = bindingSource; | ||
| } | ||
|
|
||
| return bindingsWithDefaults; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.