-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): only open one annotation object edit modal at a time (#7898)
- Loading branch information
1 parent
d98873c
commit fbecbc8
Showing
14 changed files
with
198 additions
and
59 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/PortableTextMemberItemElementRefsContext.ts
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,12 @@ | ||
import {BehaviorSubject} from 'rxjs' | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
/** @internal */ | ||
export type PortableTextEditorElement = HTMLDivElement | HTMLSpanElement | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PortableTextMemberItemElementRefsContext = createContext< | ||
BehaviorSubject<Record<string, PortableTextEditorElement | null | undefined>> | ||
>('sanity/_singletons/context/portable-text-member-item-element-refs', new BehaviorSubject({})) |
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
38 changes: 38 additions & 0 deletions
38
.../src/core/form/inputs/PortableText/contexts/PortableTextMemberItemElementRefsProvider.tsx
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,38 @@ | ||
import {useCallback, useContext} from 'react' | ||
import {useObservable} from 'react-rx' | ||
import {type PortableTextMemberItem} from 'sanity' | ||
import { | ||
type PortableTextEditorElement, | ||
PortableTextMemberItemElementRefsContext, | ||
} from 'sanity/_singletons' | ||
|
||
export type SetPortableTextMemberItemElementRef = ({ | ||
key, | ||
elementRef, | ||
}: { | ||
key: PortableTextMemberItem['member']['key'] | ||
elementRef: PortableTextEditorElement | null | ||
}) => void | ||
|
||
export function usePortableTextMemberItemElementRefs(): Record< | ||
PortableTextMemberItem['member']['key'], | ||
PortableTextEditorElement | null | undefined | ||
> { | ||
const behaviorSubject = useContext(PortableTextMemberItemElementRefsContext) | ||
|
||
return useObservable(behaviorSubject, {}) | ||
} | ||
|
||
export function useSetPortableTextMemberItemElementRef(): SetPortableTextMemberItemElementRef { | ||
const behaviorSubject = useContext(PortableTextMemberItemElementRefsContext) | ||
|
||
return useCallback<SetPortableTextMemberItemElementRef>( | ||
({key, elementRef}) => { | ||
behaviorSubject.next({ | ||
...behaviorSubject.value, | ||
[key]: elementRef, | ||
}) | ||
}, | ||
[behaviorSubject], | ||
) | ||
} |
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.