-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: flatten
_singletons
and increase usage of `sanity/_create…
…Context` (#7311) * chore: add eslint rule to prevent react.createContext * refactor: move and flatten contexts * refactor: switch to sanity/_createContext
- Loading branch information
1 parent
a9892bd
commit 15c39de
Showing
113 changed files
with
671 additions
and
515 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...eMatcher/ActiveWorkspaceMatcherContext.ts → .../context/ActiveWorkspaceMatcherContext.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
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/AddonDatasetContext.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 {createContext} from 'sanity/_createContext' | ||
|
||
import type {AddonDatasetContextValue} from '../../core/studio/addonDataset/types' | ||
|
||
/** | ||
* @beta | ||
* @hidden | ||
*/ | ||
export const AddonDatasetContext = createContext<AddonDatasetContextValue | null>( | ||
'sanity/_singletons/context/addon-dataset', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/CalendarContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
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>( | ||
'sanity/_singletons/context/calendar', | ||
undefined, | ||
) |
20 changes: 20 additions & 0 deletions
20
packages/sanity/src/_singletons/context/ChangeIndicatorTrackerContexts.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,20 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type { | ||
ChangeIndicatorTrackerContextStoreType, | ||
ChangeIndicatorTrackerGetSnapshotType, | ||
} from '../../core/changeIndicators/ChangeIndicatorTrackerContexts' | ||
|
||
/** @internal */ | ||
export const ChangeIndicatorTrackerContextStore = | ||
createContext<ChangeIndicatorTrackerContextStoreType>( | ||
'sanity/_singletons/context/change-indicator-tracker-store', | ||
null, | ||
) | ||
|
||
/** @internal */ | ||
export const ChangeIndicatorTrackerContextGetSnapshot = | ||
createContext<ChangeIndicatorTrackerGetSnapshotType>( | ||
'sanity/_singletons/context/change-indicator-tracker-get-snapshot', | ||
null, | ||
) |
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
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/ColorSchemeValueContext.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 {createContext} from 'sanity/_createContext' | ||
|
||
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>( | ||
'sanity/_singletons/context/color-scheme-value', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/CommentInputContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {CommentInputContextValue} from '../../core/comments/components/pte/comment-input/CommentInputProvider' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const CommentInputContext = createContext<CommentInputContextValue | null>( | ||
'sanity/_singletons/context/comment-input', | ||
null, | ||
) |
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/CommentsAuthoringPathContext.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 {createContext} from 'sanity/_createContext' | ||
|
||
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, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/CommentsContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {CommentsContextValue} from '../../core/comments/context/comments/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const CommentsContext = createContext<CommentsContextValue | null>( | ||
'sanity/_singletons/context/comments', | ||
null, | ||
) |
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
2 changes: 1 addition & 1 deletion
2
.../comments/intent/CommentsIntentContext.ts → ...ngletons/context/CommentsIntentContext.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
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/CommentsOnboardingContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {CommentsOnboardingContextValue} from '../../core/comments/context/onboarding/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const CommentsOnboardingContext = createContext<CommentsOnboardingContextValue | null>( | ||
'sanity/_singletons/context/comments-onboarding', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/CommentsSelectedPathContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {CommentsSelectedPathContextValue} from '../../core/comments/context/selected-path/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const CommentsSelectedPathContext = createContext<CommentsSelectedPathContextValue | null>( | ||
'sanity/_singletons/context/comments-selected-path', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/CommentsUpsellContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {CommentsUpsellContextValue} from '../../core/comments/context/upsell/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const CommentsUpsellContext = createContext<CommentsUpsellContextValue | null>( | ||
'sanity/_singletons/context/comments-upsell', | ||
null, | ||
) |
13 changes: 13 additions & 0 deletions
13
packages/sanity/src/_singletons/context/ConnectorContext.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,13 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {ConnectorContextValue} from '../../core/changeIndicators/ConnectorContext' | ||
|
||
/** @internal */ | ||
export const ConnectorContext = createContext<ConnectorContextValue>( | ||
'sanity/_singletons/context/connector', | ||
{ | ||
isReviewChangesOpen: false, | ||
onOpenReviewChanges: () => undefined, | ||
onSetFocus: () => undefined, | ||
} as ConnectorContextValue, | ||
) |
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/CopyPasteContext.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 {createContext} from 'sanity/_createContext' | ||
|
||
import type {CopyPasteContextType} from '../../core/studio/copyPaste' | ||
|
||
/** | ||
* @beta | ||
* @hidden | ||
*/ | ||
export const CopyPasteContext = createContext<CopyPasteContextType | null>( | ||
'sanity/_singletons/context/copy-paste', | ||
null, | ||
) |
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,9 @@ | ||
import type {Path} from '@sanity/types' | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
/** @internal */ | ||
export const DiffContext = createContext<{ | ||
path: Path | ||
}>('sanity/_singletons/context/diff', { | ||
path: [], | ||
}) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/DocumentActionPropsContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {DocumentActionProps} from '../../core/config/document/actions' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const DocumentActionPropsContext = createContext<DocumentActionProps | undefined>( | ||
'sanity/_singletons/context/document-action-props', | ||
undefined, | ||
) |
9 changes: 9 additions & 0 deletions
9
packages/sanity/src/_singletons/context/DocumentChangeContext.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,9 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {DocumentChangeContextInstance} from '../../core/field/diff/contexts/DocumentChangeContext' | ||
|
||
/** @internal */ | ||
export const DocumentChangeContext = createContext<DocumentChangeContextInstance | null>( | ||
'sanity/_singletons/context/document-change', | ||
null, | ||
) |
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
2 changes: 1 addition & 1 deletion
2
...ure/panes/document/DocumentPaneContext.ts → ...singletons/context/DocumentPaneContext.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
9 changes: 9 additions & 0 deletions
9
packages/sanity/src/_singletons/context/DocumentSheetListContext.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,9 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {DocumentSheetListContextValue} from '../../structure/panes/documentList/sheetList/DocumentSheetListProvider' | ||
|
||
/** @internal */ | ||
export const DocumentSheetListContext = createContext<DocumentSheetListContextValue | undefined>( | ||
'sanity/_singletons/context/document-sheet-list', | ||
undefined, | ||
) |
24 changes: 24 additions & 0 deletions
24
packages/sanity/src/_singletons/context/FieldActionsContext.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,24 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {DocumentFieldActionNode} from '../../core/config/document/fieldActions/types' | ||
|
||
/** @internal */ | ||
export interface FieldActionsContextValue { | ||
actions: DocumentFieldActionNode[] | ||
focused?: boolean | ||
hovered: boolean | ||
onMouseEnter: () => void | ||
onMouseLeave: () => void | ||
} | ||
|
||
/** @internal */ | ||
export const FieldActionsContext = createContext<FieldActionsContextValue>( | ||
'sanity/_singletons/context/field-actions', | ||
{ | ||
actions: [], | ||
focused: false, | ||
hovered: false, | ||
onMouseEnter: () => undefined, | ||
onMouseLeave: () => undefined, | ||
}, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/FormBuilderContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {FormBuilderContextValue} from '../../core/form/FormBuilderContext' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const FormBuilderContext = createContext<FormBuilderContextValue | null>( | ||
'sanity/_singletons/context/form-builder', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/FormCallbacksContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {FormCallbacksValue} from '../../core/form/studio/contexts/FormCallbacks' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const FormCallbacksContext = createContext<FormCallbacksValue | null>( | ||
'sanity/_singletons/context/form-callbacks', | ||
null, | ||
) |
9 changes: 9 additions & 0 deletions
9
packages/sanity/src/_singletons/context/FormFieldPresenceContext.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,9 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {FormNodePresence} from '../../core/presence/types' | ||
|
||
/** @internal */ | ||
export const FormFieldPresenceContext = createContext<FormNodePresence[]>( | ||
'sanity/_singletons/context/form-field-presence', | ||
[], | ||
) |
2 changes: 1 addition & 1 deletion
2
..._singletons/core/form/FormValueContext.ts → ...c/_singletons/context/FormValueContext.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
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/FreeTrialContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {FreeTrialContextProps} from '../../core/studio/components/navbar/free-trial/FreeTrialContext' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const FreeTrialContext = createContext<FreeTrialContextProps | undefined>( | ||
'sanity/_singletons/context/free-trial', | ||
undefined, | ||
) |
File renamed without changes.
Oops, something went wrong.