Skip to content

Commit

Permalink
refactor(core): move PortableTextMemberItemsContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent ed8f318 commit 6325629
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {createContext} from 'react'
import type {PortableTextMemberItem} from 'sanity'

export const PortableTextMemberItemsContext = createContext<PortableTextMemberItem[]>([])
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './form/GetFormValueContext'
export * from './form/inputs/arrays/ArrayOfObjectsInput/List/VirtualizerScrollInstanceContext'
export * from './form/inputs/arrays/common/SortableItemIdContext'
export * from './form/inputs/PortableText/PortableTextMarkersContext'
export * from './form/inputs/PortableText/PortableTextMemberItemsContext'
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {createContext, type ReactNode} from 'react'
import {type ReactNode} from 'react'
import {PortableTextMemberItemsContext} from 'sanity/_singletons'

import {type PortableTextMemberItem} from '../PortableTextInput'

export const PortableTextMemberItemsContext = createContext<PortableTextMemberItem[]>([])

export function PortableTextMemberItemsProvider(props: {
memberItems: PortableTextMemberItem[]
children: ReactNode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {pathFor} from '@sanity/util/paths'
import {createRef, type MutableRefObject, type ReactNode, useContext, useRef} from 'react'
import {PortableTextMemberItemsContext} from 'sanity/_singletons'

import {pathToString} from '../../../../field'
import {type FIXME} from '../../../../FIXME'
Expand All @@ -9,7 +10,6 @@ import {type ArrayOfObjectsItemMember, type ObjectFormNode} from '../../../store
import {type PortableTextInputProps} from '../../../types'
import {isArrayOfObjectsFieldMember, isBlockType} from '../_helpers'
import {type PortableTextEditorElement} from '../Compositor'
import {PortableTextMemberItemsContext} from '../contexts/PortableTextMembers'
import {type PortableTextMemberItem} from '../PortableTextInput'

export function usePortableTextMemberItem(key: string): PortableTextMemberItem | undefined {
Expand Down

0 comments on commit 6325629

Please sign in to comment.