Skip to content

Commit

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

/**
* @internal
*/
export const FormCallbacksContext = createContext<FormCallbacksValue | null>(null)
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './form/inputs/PortableText/PortableTextMarkersContext'
export * from './form/inputs/PortableText/PortableTextMemberItemsContext'
export * from './form/inputs/ReferenceInput/ReferenceItemRefContext'
export * from './form/studio/DocumentFieldActionsContext'
export * from './form/studio/FormCallbacksContext'
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/no-unused-prop-types */
import {type Path} from '@sanity/types'
import {createContext, memo, type ReactNode, useCallback, useContext, useMemo, useRef} from 'react'
import {memo, type ReactNode, useCallback, useContext, useMemo, useRef} from 'react'
import {FormCallbacksContext} from 'sanity/_singletons'

import {type OnPathFocusPayload} from '../..'
import {type FormPatch, type PatchEvent} from '../../patch'
Expand All @@ -17,11 +18,6 @@ export interface FormCallbacksValue {
onFieldGroupSelect: (path: Path, fieldGroupName: string) => void
}

/**
* @internal
*/
export const FormCallbacksContext = createContext<FormCallbacksValue | null>(null)

/** @internal */
export const FormCallbacksProvider = memo(function FormCallbacksProvider(
props: FormCallbacksValue & {children: ReactNode},
Expand Down
3 changes: 2 additions & 1 deletion packages/sanity/src/core/form/utils/TransformPatches.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {memo, type ReactNode, useCallback, useMemo} from 'react'
import {FormCallbacksContext} from 'sanity/_singletons'

import {type FormPatch, PatchEvent} from '../patch'
import {FormCallbacksContext, useFormCallbacks} from '../studio'
import {useFormCallbacks} from '../studio'

type PatchTransformer = (patches: FormPatch[]) => FormPatch[]

Expand Down

0 comments on commit 2518910

Please sign in to comment.