-
Notifications
You must be signed in to change notification settings - Fork 4.6k
SlotFill: Migrate to Typescript. #51350
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
50 commits
Select commit
Hold shift + click to select a range
a0bbcbf
convert typescript slot-fill-context.ts and slot-fill-provider.tsx
torounit 353f3bf
fix portalContainer type.
torounit 46e4983
convert hooks to ts.
torounit 49b7807
fix types
torounit f7f3c07
fix fillProps
torounit e7dbaf1
convert slot.tsx
torounit f3d474f
update Fill
torounit e4f205c
fix typename.
torounit 94219ca
fix dropdown v2 portal container type.
torounit 83466fc
fix ref type
torounit e333f1b
refactor
torounit 681a0e8
refactor SlotFillProvider
torounit c7419ed
migrate SlotComponent to TS
torounit 7703647
convert useSlot
torounit 7862088
add update
torounit e03bc11
fix ProviderProps
torounit b50ae79
refactor type
torounit 4e0a665
refactor type
torounit 499f8bd
allow symbol to name prop.
torounit 228fd5f
refactor SlotComponentProps
torounit fe872f9
refactor stroies and README
torounit ebfd7f3
fix typo
torounit bbffb58
remove comments. remove children from Slot.
torounit 1182668
refactor SlotComponentProps
torounit e5a828e
Apply suggestions from code review
torounit 79951ea
Apply suggestions from code review
torounit 4deef29
refactor: newChildren to inline.
torounit 5e26c79
Remove unnecessary type variables.
torounit 0f6d79c
fix type comments
torounit 46ff121
Remove unnecessary Type Guards. Remove unnecessary Type Guards. And u…
torounit 68f277c
remove type from jsdoc
torounit cf48aee
refactor types
torounit 9695182
refactor types
torounit 09b23ce
Simplify the type of `slot`.
torounit d515975
Remove the type specification and leave it to type inference.
torounit d650f5f
fix types
torounit 3b12a6d
remove story.js
torounit 191a45d
update changelog
torounit 82349c0
remove ts-nocheck
torounit 78ab5e7
fix story filename. remove override bubblesVirtually attribute
torounit 821f4d4
replace useState to useMemo
torounit 0607a32
switch to ts-expect-error in story.
torounit 81bd81d
fix mssing changelog https://github.com/WordPress/gutenberg/pull/5327…
torounit 2e7e367
add `children?: never` https://github.com/WordPress/gutenberg/pull/51…
torounit d5773d4
use Record
torounit f169e67
use Record / Enable className only when bubblesVirtually: true.
torounit 2cc685f
Update packages/components/src/slot-fill/types.ts
torounit 31ba069
update changelog
torounit 656a45d
use optional chain
torounit ff18ed5
fix WordPressComponentProps import
torounit 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 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
95 changes: 0 additions & 95 deletions
95
packages/components/src/slot-fill/bubbles-virtually/slot-fill-provider.js
This file was deleted.
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
packages/components/src/slot-fill/bubbles-virtually/slot-fill-provider.tsx
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,115 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { ref as valRef } from 'valtio'; | ||
| import { proxyMap } from 'valtio/utils'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMemo } from '@wordpress/element'; | ||
| import isShallowEqual from '@wordpress/is-shallow-equal'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import SlotFillContext from './slot-fill-context'; | ||
| import type { | ||
| SlotFillProviderProps, | ||
| SlotFillBubblesVirtuallyContext, | ||
| } from '../types'; | ||
|
|
||
| function createSlotRegistry(): SlotFillBubblesVirtuallyContext { | ||
| const slots: SlotFillBubblesVirtuallyContext[ 'slots' ] = proxyMap(); | ||
| const fills: SlotFillBubblesVirtuallyContext[ 'fills' ] = proxyMap(); | ||
|
|
||
| const registerSlot: SlotFillBubblesVirtuallyContext[ 'registerSlot' ] = ( | ||
| name, | ||
| ref, | ||
| fillProps | ||
| ) => { | ||
| const slot = slots.get( name ); | ||
|
|
||
| slots.set( | ||
| name, | ||
| valRef( { | ||
| ...slot, | ||
| ref: ref || slot?.ref, | ||
| fillProps: fillProps || slot?.fillProps || {}, | ||
| } ) | ||
| ); | ||
| }; | ||
|
|
||
| const unregisterSlot: SlotFillBubblesVirtuallyContext[ 'unregisterSlot' ] = | ||
| ( name, ref ) => { | ||
| // Make sure we're not unregistering a slot registered by another element | ||
| // See https://github.com/WordPress/gutenberg/pull/19242#issuecomment-590295412 | ||
| if ( slots.get( name )?.ref === ref ) { | ||
| slots.delete( name ); | ||
| } | ||
| }; | ||
|
|
||
| const updateSlot: SlotFillBubblesVirtuallyContext[ 'updateSlot' ] = ( | ||
| name, | ||
| fillProps | ||
| ) => { | ||
| const slot = slots.get( name ); | ||
| if ( ! slot ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( isShallowEqual( slot.fillProps, fillProps ) ) { | ||
| return; | ||
| } | ||
|
|
||
| slot.fillProps = fillProps; | ||
| const slotFills = fills.get( name ); | ||
| if ( slotFills ) { | ||
| // Force update fills. | ||
| slotFills.map( ( fill ) => fill.current.rerender() ); | ||
| } | ||
| }; | ||
|
|
||
| const registerFill: SlotFillBubblesVirtuallyContext[ 'registerFill' ] = ( | ||
| name, | ||
| ref | ||
| ) => { | ||
| fills.set( name, valRef( [ ...( fills.get( name ) || [] ), ref ] ) ); | ||
| }; | ||
|
|
||
| const unregisterFill: SlotFillBubblesVirtuallyContext[ 'registerFill' ] = ( | ||
| name, | ||
| ref | ||
| ) => { | ||
| const fillsForName = fills.get( name ); | ||
| if ( ! fillsForName ) { | ||
| return; | ||
| } | ||
|
|
||
| fills.set( | ||
| name, | ||
| valRef( fillsForName.filter( ( fillRef ) => fillRef !== ref ) ) | ||
| ); | ||
| }; | ||
|
|
||
| return { | ||
| slots, | ||
| fills, | ||
| registerSlot, | ||
| updateSlot, | ||
| unregisterSlot, | ||
| registerFill, | ||
| unregisterFill, | ||
| }; | ||
| } | ||
|
|
||
| export default function SlotFillProvider( { | ||
| children, | ||
| }: SlotFillProviderProps ) { | ||
| const registry = useMemo( createSlotRegistry, [] ); | ||
| return ( | ||
| <SlotFillContext.Provider value={ registry }> | ||
| { children } | ||
| </SlotFillContext.Provider> | ||
| ); | ||
| } |
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.
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.