-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "SlotFill: Migrate to Typescript. (#51350)"
This reverts commit 3cca31c.
- Loading branch information
Showing
21 changed files
with
377 additions
and
682 deletions.
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
95 changes: 95 additions & 0 deletions
95
packages/components/src/slot-fill/bubbles-virtually/slot-fill-provider.js
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// @ts-nocheck | ||
/** | ||
* External dependencies | ||
*/ | ||
import { ref as valRef } from 'valtio'; | ||
import { proxyMap } from 'valtio/utils'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import isShallowEqual from '@wordpress/is-shallow-equal'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SlotFillContext from './slot-fill-context'; | ||
|
||
function createSlotRegistry() { | ||
const slots = proxyMap(); | ||
const fills = proxyMap(); | ||
|
||
function registerSlot( name, ref, fillProps ) { | ||
const slot = slots.get( name ) || {}; | ||
slots.set( | ||
name, | ||
valRef( { | ||
...slot, | ||
ref: ref || slot.ref, | ||
fillProps: fillProps || slot.fillProps || {}, | ||
} ) | ||
); | ||
} | ||
|
||
function 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 ); | ||
} | ||
} | ||
|
||
function 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() ); | ||
} | ||
} | ||
|
||
function registerFill( name, ref ) { | ||
fills.set( name, valRef( [ ...( fills.get( name ) || [] ), ref ] ) ); | ||
} | ||
|
||
function unregisterFill( 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 } ) { | ||
const [ registry ] = useState( createSlotRegistry ); | ||
return ( | ||
<SlotFillContext.Provider value={ registry }> | ||
{ children } | ||
</SlotFillContext.Provider> | ||
); | ||
} |
115 changes: 0 additions & 115 deletions
115
packages/components/src/slot-fill/bubbles-virtually/slot-fill-provider.tsx
This file was deleted.
Oops, something went wrong.
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.