Skip to content

Commit

Permalink
refactor: switch to sanity/_createContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Aug 3, 2024
1 parent 922f6de commit 03294df
Show file tree
Hide file tree
Showing 67 changed files with 458 additions and 307 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'sanity/_createContext'

import type {ActiveWorkspaceMatcherContextValue} from '../../../../core/studio/activeWorkspaceMatcher/ActiveWorkspaceMatcherContext'
import type {ActiveWorkspaceMatcherContextValue} from '../../core/studio/activeWorkspaceMatcher/ActiveWorkspaceMatcherContext'

/** @internal */
export const ActiveWorkspaceMatcherContext =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {AddonDatasetContextValue} from '../../../../core/studio/addonDataset/types'
import type {AddonDatasetContextValue} from '../../core/studio/addonDataset/types'

/**
* @beta
* @hidden
*/
export const AddonDatasetContext = createContext<AddonDatasetContextValue | null>(null)
export const AddonDatasetContext = createContext<AddonDatasetContextValue | null>(
'sanity/_singletons/context/addon-dataset',
null,
)
9 changes: 6 additions & 3 deletions packages/sanity/src/_singletons/context/CalendarContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CalendarContextValue} from '../../../../../../../../../../../../../core/studio/components/navbar/search/components/filters/filter/inputs/date/datePicker/calendar/contexts/CalendarContext'
import type {CalendarContextValue} from '../../core/studio/components/navbar/search/components/filters/filter/inputs/date/datePicker/calendar/contexts/CalendarContext'

/**
* @internal
*/
export const CalendarContext = createContext<CalendarContextValue | undefined>(undefined)
export const CalendarContext = createContext<CalendarContextValue | undefined>(
'sanity/_singletons/context/calendar',
undefined,
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {
ChangeIndicatorTrackerContextStoreType,
ChangeIndicatorTrackerGetSnapshotType,
} from '../../../core/changeIndicators/ChangeIndicatorTrackerContexts'
} from '../../core/changeIndicators/ChangeIndicatorTrackerContexts'

/** @internal */
export const ChangeIndicatorTrackerContextStore =
createContext<ChangeIndicatorTrackerContextStoreType>(null)
createContext<ChangeIndicatorTrackerContextStoreType>(
'sanity/_singletons/context/change-indicator-tracker-store',
null,
)

/** @internal */
export const ChangeIndicatorTrackerContextGetSnapshot =
createContext<ChangeIndicatorTrackerGetSnapshotType>(null)
createContext<ChangeIndicatorTrackerGetSnapshotType>(
'sanity/_singletons/context/change-indicator-tracker-get-snapshot',
null,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {StudioThemeColorSchemeKey} from '../../../core/theme/types'
import type {StudioThemeColorSchemeKey} from '../../core/theme/types'

/**
* The setter for ColorSchemeValueContext, in a separate context to avoid unnecessary re-renders
Expand All @@ -9,4 +9,4 @@ import type {StudioThemeColorSchemeKey} from '../../../core/theme/types'
*/
export const ColorSchemeSetValueContext = createContext<
((nextScheme: StudioThemeColorSchemeKey) => void) | false | null
>(null)
>('sanity/_singletons/context/color-scheme-set-value', null)
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {StudioThemeColorSchemeKey} from '../../../core/theme/types'
import type {StudioThemeColorSchemeKey} from '../../core/theme/types'

/**
* Used to keep track of the internal value, which can be "system" in addition to "light" and "dark"
* @internal
*/
export const ColorSchemeValueContext = createContext<StudioThemeColorSchemeKey | null>(null)
export const ColorSchemeValueContext = createContext<StudioThemeColorSchemeKey | null>(
'sanity/_singletons/context/color-scheme-value',
null,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentInputContextValue} from '../../../../../../core/comments/components/pte/comment-input/CommentInputProvider'
import type {CommentInputContextValue} from '../../core/comments/components/pte/comment-input/CommentInputProvider'

/**
* @internal
*/
export const CommentInputContext = createContext<CommentInputContextValue | null>(null)
export const CommentInputContext = createContext<CommentInputContextValue | null>(
'sanity/_singletons/context/comment-input',
null,
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentsAuthoringPathContextValue} from '../../../../core/comments/context/authoring-path/types'
import type {CommentsAuthoringPathContextValue} from '../../core/comments/context/authoring-path/types'

/**
* @beta
* @hidden
*/
export const CommentsAuthoringPathContext = createContext<CommentsAuthoringPathContextValue | null>(
'sanity/_singletons/context/comments-authoring-path',
null,
)
9 changes: 6 additions & 3 deletions packages/sanity/src/_singletons/context/CommentsContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentsContextValue} from '../../../core/comments/context/comments/types'
import type {CommentsContextValue} from '../../core/comments/context/comments/types'

/**
* @internal
*/
export const CommentsContext = createContext<CommentsContextValue | null>(null)
export const CommentsContext = createContext<CommentsContextValue | null>(
'sanity/_singletons/context/comments',
null,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentsEnabledContextValue} from '../../../../core/comments/context/enabled/types'
import type {CommentsEnabledContextValue} from '../../core/comments/context/enabled/types'

// NOTE: We initialize this context with a default value (`enabled: false`)
// rather than `null` to handle cases where the comments feature's availability
Expand All @@ -11,7 +11,10 @@ import type {CommentsEnabledContextValue} from '../../../../core/comments/contex
/**
* @internal
*/
export const CommentsEnabledContext = createContext<CommentsEnabledContextValue>({
enabled: false,
mode: null,
})
export const CommentsEnabledContext = createContext<CommentsEnabledContextValue>(
'sanity/_singletons/context/comments-enabled',
{
enabled: false,
mode: null,
},
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'sanity/_createContext'

import type {CommentsIntentContextValue} from '../../../../core/comments/context/intent/types'
import type {CommentsIntentContextValue} from '../../core/comments/context/intent/types'

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentsOnboardingContextValue} from '../../../../core/comments/context/onboarding/types'
import type {CommentsOnboardingContextValue} from '../../core/comments/context/onboarding/types'

/**
* @internal
*/
export const CommentsOnboardingContext = createContext<CommentsOnboardingContextValue | null>(null)
export const CommentsOnboardingContext = createContext<CommentsOnboardingContextValue | null>(
'sanity/_singletons/context/comments-onboarding',
null,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentsSelectedPathContextValue} from '../../../../core/comments/context/selected-path/types'
import type {CommentsSelectedPathContextValue} from '../../core/comments/context/selected-path/types'

/**
* @internal
*/
export const CommentsSelectedPathContext = createContext<CommentsSelectedPathContextValue | null>(
'sanity/_singletons/context/comments-selected-path',
null,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CommentsUpsellContextValue} from '../../../../core/comments/context/upsell/types'
import type {CommentsUpsellContextValue} from '../../core/comments/context/upsell/types'

/**
* @internal
*/
export const CommentsUpsellContext = createContext<CommentsUpsellContextValue | null>(null)
export const CommentsUpsellContext = createContext<CommentsUpsellContextValue | null>(
'sanity/_singletons/context/comments-upsell',
null,
)
17 changes: 10 additions & 7 deletions packages/sanity/src/_singletons/context/ConnectorContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {ConnectorContextValue} from '../../../core/changeIndicators/ConnectorContext'
import type {ConnectorContextValue} from '../../core/changeIndicators/ConnectorContext'

/** @internal */
export const ConnectorContext = createContext<ConnectorContextValue>({
isReviewChangesOpen: false,
onOpenReviewChanges: () => undefined,
onSetFocus: () => undefined,
} as ConnectorContextValue)
export const ConnectorContext = createContext<ConnectorContextValue>(
'sanity/_singletons/context/connector',
{
isReviewChangesOpen: false,
onOpenReviewChanges: () => undefined,
onSetFocus: () => undefined,
} as ConnectorContextValue,
)
9 changes: 6 additions & 3 deletions packages/sanity/src/_singletons/context/CopyPasteContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {CopyPasteContextType} from '../../../../core/studio/copyPaste'
import type {CopyPasteContextType} from '../../core/studio/copyPaste'

/**
* @beta
* @hidden
*/
export const CopyPasteContext = createContext<CopyPasteContextType | null>(null)
export const CopyPasteContext = createContext<CopyPasteContextType | null>(
'sanity/_singletons/context/copy-paste',
null,
)
8 changes: 6 additions & 2 deletions packages/sanity/src/_singletons/context/DiffContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type {Path} from '@sanity/types'
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

/** @internal */
export const DiffContext = createContext<{path: Path}>({path: []})
export const DiffContext = createContext<{
path: Path
}>('sanity/_singletons/context/diff', {
path: [],
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {DocumentActionProps} from '../../../core/config/document/actions'
import type {DocumentActionProps} from '../../core/config/document/actions'

/**
* @internal
*/
export const DocumentActionPropsContext = createContext<DocumentActionProps | undefined>(undefined)
export const DocumentActionPropsContext = createContext<DocumentActionProps | undefined>(
'sanity/_singletons/context/document-action-props',
undefined,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {DocumentChangeContextInstance} from '../../../../core/field/diff/contexts/DocumentChangeContext'
import type {DocumentChangeContextInstance} from '../../core/field/diff/contexts/DocumentChangeContext'

/** @internal */
export const DocumentChangeContext = createContext<DocumentChangeContextInstance | null>(null)
export const DocumentChangeContext = createContext<DocumentChangeContextInstance | null>(
'sanity/_singletons/context/document-change',
null,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {DocumentFieldAction} from '../../../../core/config/document/fieldActions/types'
import type {DocumentFieldAction} from '../../core/config/document/fieldActions/types'

/**
* @internal
Expand All @@ -13,5 +13,6 @@ export interface DocumentFieldActionsContextValue {
* @internal
*/
export const DocumentFieldActionsContext = createContext<DocumentFieldActionsContextValue | null>(
'sanity/_singletons/context/document-field-actions',
null,
)
7 changes: 5 additions & 2 deletions packages/sanity/src/_singletons/context/DocumentIdContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

/**
* @internal
Expand All @@ -10,4 +10,7 @@ export interface DocumentIdContextValue {
/**
* @internal
*/
export const DocumentIdContext = createContext<DocumentIdContextValue | null>(null)
export const DocumentIdContext = createContext<DocumentIdContextValue | null>(
'sanity/_singletons/context/document-id',
null,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'sanity/_createContext'

import type {DocumentPaneContextValue} from '../../../../structure/panes/document/DocumentPaneContext'
import type {DocumentPaneContextValue} from '../../structure/panes/document/DocumentPaneContext'

/** @internal */
export const DocumentPaneContext = createContext<DocumentPaneContextValue | null>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {DocumentSheetListContextValue} from '../../../../structure/panes/documentList/sheetList/DocumentSheetListProvider'
import type {DocumentSheetListContextValue} from '../../structure/panes/documentList/sheetList/DocumentSheetListProvider'

/** @internal */
export const DocumentSheetListContext = createContext<DocumentSheetListContextValue | undefined>(
'sanity/_singletons/context/document-sheet-list',
undefined,
)
21 changes: 12 additions & 9 deletions packages/sanity/src/_singletons/context/FieldActionsContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {DocumentFieldActionNode} from '../../../../../core/config/document/fieldActions/types'
import type {DocumentFieldActionNode} from '../../core/config/document/fieldActions/types'

/** @internal */
export interface FieldActionsContextValue {
Expand All @@ -12,10 +12,13 @@ export interface FieldActionsContextValue {
}

/** @internal */
export const FieldActionsContext = createContext<FieldActionsContextValue>({
actions: [],
focused: false,
hovered: false,
onMouseEnter: () => undefined,
onMouseLeave: () => undefined,
})
export const FieldActionsContext = createContext<FieldActionsContextValue>(
'sanity/_singletons/context/field-actions',
{
actions: [],
focused: false,
hovered: false,
onMouseEnter: () => undefined,
onMouseLeave: () => undefined,
},
)
9 changes: 6 additions & 3 deletions packages/sanity/src/_singletons/context/FormBuilderContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext} from 'react'
import {createContext} from 'sanity/_createContext'

import type {FormBuilderContextValue} from '../../../core/form/FormBuilderContext'
import type {FormBuilderContextValue} from '../../core/form/FormBuilderContext'

/**
* @internal
*/
export const FormBuilderContext = createContext<FormBuilderContextValue | null>(null)
export const FormBuilderContext = createContext<FormBuilderContextValue | null>(
'sanity/_singletons/context/form-builder',
null,
)
Loading

0 comments on commit 03294df

Please sign in to comment.