Skip to content

Commit

Permalink
refactor(core): move FormBuilderContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 0509e58 commit 0f9cf43
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
7 changes: 7 additions & 0 deletions packages/sanity/src/_singletons/form/FormBuilderContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createContext} from 'react'
import type {FormBuilderContextValue} from 'sanity'

/**
* @internal
*/
export const FormBuilderContext = createContext<FormBuilderContextValue | 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 @@ -5,3 +5,4 @@ export * from './components/zOffsets/ZIndexContext'
export * from './components/zOffsets/zIndexContextDefaults'
export * from './field/diff/DiffContext'
export * from './field/diff/DocumentChangeContext'
export * from './form/FormBuilderContext'
6 changes: 0 additions & 6 deletions packages/sanity/src/core/form/FormBuilderContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {type AssetSource, type ObjectSchemaType, type Path} from '@sanity/types'
import {createContext} from 'react'

import {type PatchChannel} from './patch'
import {type FormFieldGroup, type StateTree} from './store'
Expand Down Expand Up @@ -60,8 +59,3 @@ export interface FormBuilderContextValue {
renderPreview: RenderPreviewCallback
schemaType: ObjectSchemaType
}

/**
* @internal
*/
export const FormBuilderContext = createContext<FormBuilderContextValue | null>(null)
3 changes: 2 additions & 1 deletion packages/sanity/src/core/form/FormBuilderProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import {type ObjectSchemaType, type Path, type ValidationMarker} from '@sanity/types'
import {type ReactNode, useMemo} from 'react'
import {FormBuilderContext} from 'sanity/_singletons'

import {type DocumentFieldAction, type Source} from '../config'
import {type FormNodePresence} from '../presence'
import {EMPTY_ARRAY} from '../util'
import {DocumentIdProvider} from './contexts/DocumentIdProvider'
import {HoveredFieldProvider} from './field'
import {FormBuilderContext, type FormBuilderContextValue} from './FormBuilderContext'
import {type FormBuilderContextValue} from './FormBuilderContext'
import {ArrayOfObjectsFunctions} from './inputs/arrays/ArrayOfObjectsInput/ArrayOfObjectsFunctions'
import {DefaultCustomMarkers} from './inputs/PortableText/_legacyDefaultParts/CustomMarkers'
import {DefaultMarkers} from './inputs/PortableText/_legacyDefaultParts/Markers'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {LayerProvider, studioTheme, ThemeProvider} from '@sanity/ui'
import {render} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import {type PropsWithChildren} from 'react'
import {FormBuilderContext} from 'sanity/_singletons'

import {type FIXME} from '../../../../FIXME'
import {DocumentIdProvider} from '../../../contexts/DocumentIdProvider'
import {FormBuilderContext, type FormBuilderContextValue} from '../../../FormBuilderContext'
import {type FormBuilderContextValue} from '../../../FormBuilderContext'
import {PatchEvent, set} from '../../../patch'
import {type FieldMember} from '../../../store'
import {
Expand Down
3 changes: 2 additions & 1 deletion packages/sanity/src/core/form/useFormBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useContext} from 'react'
import {FormBuilderContext} from 'sanity/_singletons'

import {FormBuilderContext, type FormBuilderContextValue} from './FormBuilderContext'
import {type FormBuilderContextValue} from './FormBuilderContext'

/**
*
Expand Down

0 comments on commit 0f9cf43

Please sign in to comment.