Skip to content

Commit

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

/** @internal */
export const ConnectorContext = createContext<ConnectorContextValue>({
isReviewChangesOpen: false,
onOpenReviewChanges: () => undefined,
onSetFocus: () => undefined,
} as ConnectorContextValue)
5 changes: 1 addition & 4 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/**
* @internal
*/
export const hello = 'world'
export * from './changeIndicators/ConnectorContext'
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {type Path} from '@sanity/types'
import * as PathUtils from '@sanity/util/paths'
import {type ReactNode, type SyntheticEvent, useCallback, useContext, useRef, useState} from 'react'
import deepCompare from 'react-fast-compare'
import {ConnectorContext} from 'sanity/_singletons'

import {ConnectorContext} from './ConnectorContext'
import {useReporter} from './tracker'

/**
Expand Down
8 changes: 0 additions & 8 deletions packages/sanity/src/core/changeIndicators/ConnectorContext.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {type Path} from '@sanity/types'
import {createContext} from 'react'

/** @internal */
export interface ConnectorContextValue {
isReviewChangesOpen: boolean
onOpenReviewChanges: () => void | undefined
onSetFocus: (nextPath: Path) => void | undefined
}

/** @internal */
export const ConnectorContext = createContext<ConnectorContextValue>({
isReviewChangesOpen: false,
onOpenReviewChanges: () => undefined,
onSetFocus: () => undefined,
} as ConnectorContextValue)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {useLayer} from '@sanity/ui'
import {type ReactNode, useContext, useMemo} from 'react'
import {ConnectorContext} from 'sanity/_singletons'

import {Tooltip} from '../../ui-components'
import {useTranslation} from '../i18n/hooks/useTranslation'
import {ConnectorContext} from './ConnectorContext'
import {
ChangeBar,
ChangeBarButton,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {type Path} from '@sanity/types'
import {type ReactNode, useMemo, useState} from 'react'
import {ConnectorContext} from 'sanity/_singletons'

import {ScrollContainer} from '../../components/scroll'
import {ConnectorContext} from '../ConnectorContext'
import {ENABLED} from '../constants'
import {Tracker} from '../tracker'
import {ConnectorsOverlay} from './ConnectorsOverlay'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
useMemo,
useState,
} from 'react'
import {ConnectorContext} from 'sanity/_singletons'
import {styled} from 'styled-components'

import {Popover} from '../../../../../../ui-components'
import {ConnectorContext, useReportedValues} from '../../../../../changeIndicators'
import {useReportedValues} from '../../../../../changeIndicators'
import {useTranslation} from '../../../../../i18n'
import {ChangeList, DiffContext, DiffTooltip, useDiffAnnotationColor} from '../../../../diff'
import {type ObjectDiff} from '../../../../types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {type Path, type PortableTextTextBlock} from '@sanity/types'
import {Box, Card, Stack, Text} from '@sanity/ui'
import {type MouseEvent, useCallback, useContext} from 'react'
import {ConnectorContext} from 'sanity/_singletons'

import {ConnectorContext} from '../../../../../changeIndicators'
import {useTranslation} from '../../../../../i18n'
import {DiffContext, DiffTooltip, useDiffAnnotationColor} from '../../../../diff'
import {isHeader} from '../helpers'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
import {Card, Flex, Text, useClickOutside} from '@sanity/ui'
import {FOCUS_TERMINATOR, toString} from '@sanity/util/paths'
import {type MouseEvent, useCallback, useContext, useEffect, useMemo, useState} from 'react'
import {ConnectorContext} from 'sanity/_singletons'
import {styled} from 'styled-components'

import {Popover} from '../../../../../../ui-components'
import {ConnectorContext, useReportedValues} from '../../../../../changeIndicators'
import {useReportedValues} from '../../../../../changeIndicators'
import {useTranslation} from '../../../../../i18n'
import {Preview} from '../../../../../preview/components/Preview'
import {ChangeList, DiffContext, DiffTooltip, useDiffAnnotationColor} from '../../../../diff'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {isKeySegment, type Path} from '@sanity/types'
import {type HTMLProps, type SyntheticEvent, useCallback, useContext, useMemo} from 'react'
import {ConnectorContext} from 'sanity/_singletons'

import {ConnectorContext} from '../../../../../changeIndicators'
import {useTranslation} from '../../../../../i18n'
import {DiffCard, DiffContext} from '../../../../diff'
import {type ObjectDiff, type StringDiff, type StringDiffSegment} from '../../../../types'
Expand Down

0 comments on commit 3008a1c

Please sign in to comment.