Skip to content

Commit

Permalink
refactor(core): move DocumentChangeContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent ef08d0a commit 0509e58
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 17 deletions.
87 changes: 87 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,93 @@ const config = {
'sort-imports': 'off', // handled by simple-import-sort
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
<<<<<<< HEAD
=======
'boundaries/element-types': [
'error',
{
default: 'disallow',
rules: [
{
// export
from: 'sanity/_internal',
allow: ['sanity/_internal__contents'],
},
{
from: 'sanity/_internal__contents',
allow: ['sanity', 'sanity/_internal__contents'],
},
{
// export
from: 'sanity/cli',
allow: ['sanity/cli__contents'],
},
{
from: 'sanity/cli__contents',
allow: ['sanity/cli__contents'],
},
{
// export
from: 'sanity',
allow: ['sanity__contents'],
},
{
from: 'sanity__contents',
allow: ['sanity__contents', 'sanity/router', 'sanity/_singletons'],
},
{
// export (deprecated, aliases structure)
from: 'sanity/desk',
allow: ['sanity/desk__contents', 'sanity/structure', 'sanity/structure__contents'],
},
{
from: 'sanity/desk__contents',
allow: [
'sanity',
'sanity/desk__contents',
'sanity/router',
'sanity/_internal',
'sanity/structure',
'sanity/structure__contents',
'sanity/_singletons',
],
},
{
// export
from: 'sanity/router',
allow: ['sanity/router__contents'],
},
{
from: 'sanity/router__contents',
allow: ['sanity/router__contents'],
},
{
// export
from: 'sanity/structure',
allow: ['sanity/structure__contents'],
},
{
from: 'sanity/structure__contents',
allow: ['sanity', 'sanity/structure__contents', 'sanity/router', 'sanity/_singletons'],
},
{
// export
from: 'sanity/_singletons',
allow: ['sanity/_singletons__contents'],
},
{
from: 'sanity/_singletons__contents',
allow: ['sanity/_singletons__contents'],
},
{
from: 'sanity/_singletons__contents',
allow: ['sanity'],
importKind: 'type',
},
],
},
],
>>>>>>> d55e72f356 (refactor(core): move DocumentChangeContext to singletons)
'no-undef': 'off',
'no-dupe-class-members': 'off', // doesn't work with TS overrides
'no-shadow': 'off',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {createContext} from 'react'
import type {DocumentChangeContextInstance} from 'sanity'

/** @internal */
export const DocumentChangeContext = createContext<DocumentChangeContextInstance | 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 @@ -4,3 +4,4 @@ export * from './components/scroll/scrollContext'
export * from './components/zOffsets/ZIndexContext'
export * from './components/zOffsets/zIndexContextDefaults'
export * from './field/diff/DiffContext'
export * from './field/diff/DocumentChangeContext'
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {type ObjectSchemaType} from '@sanity/types'
import {Card, Container} from '@sanity/ui'
import {useCallback, useMemo} from 'react'
import {DocumentChangeContext} from 'sanity/_singletons'

import {useSchema} from '../../hooks'
import {ChangeList, DocumentChangeContext, type DocumentChangeContextInstance} from '../diff'
import {ChangeList, type DocumentChangeContextInstance} from '../diff'
import {type ObjectDiff, type StringDiff} from '../types'

export default function ChangeListStory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {type ObjectSchemaType} from '@sanity/types'
import {Box, Card} from '@sanity/ui'
import {useCallback, useMemo} from 'react'
import {DocumentChangeContext} from 'sanity/_singletons'

import {useSchema} from '../../hooks'
import {ChangeResolver, DocumentChangeContext, type DocumentChangeContextInstance} from '../diff'
import {ChangeResolver, type DocumentChangeContextInstance} from '../diff'
import {type FieldChangeNode, type ObjectDiff, type StringDiff} from '../types'

export default function ChangeResolverStory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type Path, type SanityDocument, type SchemaType} from '@sanity/types'
import {type ComponentType, createContext, type ReactNode} from 'react'
import {type ComponentType, type ReactNode} from 'react'

import {type ObjectDiff} from '../../types'

Expand All @@ -12,6 +12,3 @@ export type DocumentChangeContextInstance = {
FieldWrapper: ComponentType<{path: Path; children: ReactNode; hasHover: boolean}>
value: Partial<SanityDocument>
}

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

import {
DocumentChangeContext,
type DocumentChangeContextInstance,
} from '../contexts/DocumentChangeContext'
import {type DocumentChangeContextInstance} from '../contexts/DocumentChangeContext'

/** @internal */
export function useDocumentChange(): DocumentChangeContextInstance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import {Box, Card, Code, Flex, Inline, Stack, Text} from '@sanity/ui'
import {format} from 'date-fns'
import {omit} from 'lodash'
import {useCallback, useMemo, useState} from 'react'
import {DocumentChangeContext} from 'sanity/_singletons'

import {Button} from '../../../../ui-components'
import {ChangeFieldWrapper} from '../../../changeIndicators'
import {
ChangeList,
type Chunk,
DocumentChangeContext,
type DocumentChangeContextInstance,
} from '../../../field'
import {ChangeList, type Chunk, type DocumentChangeContextInstance} from '../../../field'
import {useConnectionState, useEditState, useSchema} from '../../../hooks'
import {useInitialValue} from '../document'
import {useTimelineSelector, useTimelineStore} from '../history'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ChangeFieldWrapper,
ChangeList,
DiffTooltip,
DocumentChangeContext,
type DocumentChangeContextInstance,
type DocumentInspectorProps,
LoadingBlock,
Expand All @@ -16,6 +15,7 @@ import {
useTimelineSelector,
useTranslation,
} from 'sanity'
import {DocumentChangeContext} from 'sanity/_singletons'
import {styled} from 'styled-components'

import {DocumentInspectorHeader} from '../../documentInspector'
Expand Down

0 comments on commit 0509e58

Please sign in to comment.