-
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: migrate
@sanity/presentation
codebase (#8312)
- Loading branch information
Showing
103 changed files
with
11,632 additions
and
73 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
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from '@sanity/presentation' | ||
export * from '../presentation' |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/PresentationContext.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 {PresentationContextValue} from '../../presentation/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationContext = createContext<PresentationContextValue | null>( | ||
'sanity/_singletons/context/presentation', | ||
null, | ||
) |
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/PresentationDisplayedDocumentContext.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 {PresentationDisplayedDocumentContextValue} from '../../presentation/loader/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationDisplayedDocumentContext = | ||
createContext<PresentationDisplayedDocumentContextValue | null>( | ||
'sanity/_singletons/context/presentation/displayed-document', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/PresentationDocumentContext.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 {PresentationDocumentContextValue} from '../../presentation/document/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationDocumentContext = createContext<PresentationDocumentContextValue | null>( | ||
'sanity/_singletons/context/presentation/document', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/PresentationNavigateContext.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 {PresentationNavigateContextValue} from '../../presentation/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationNavigateContext = createContext<PresentationNavigateContextValue | null>( | ||
'sanity/_singletons/context/presentation/navigate', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/PresentationPanelsContext.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 {PresentationPanelsContextValue} from '../../presentation/panels/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationPanelsContext = createContext<PresentationPanelsContextValue | null>( | ||
'sanity/_singletons/context/presentation/panels', | ||
null, | ||
) |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/PresentationParamsContext.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 {PresentationParamsContextValue} from '../../presentation/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationParamsContext = createContext<PresentationParamsContextValue | null>( | ||
'sanity/_singletons/context/presentation/params', | ||
null, | ||
) |
12 changes: 12 additions & 0 deletions
12
packages/sanity/src/_singletons/context/PresentationSharedStateContext.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 {PresentationSharedStateContextValue} from '../../presentation/overlays/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PresentationSharedStateContext = | ||
createContext<PresentationSharedStateContextValue | null>( | ||
'sanity/_singletons/context/presentation/shared-state', | ||
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
29 changes: 29 additions & 0 deletions
29
packages/sanity/src/presentation/PostMessagePerspective.tsx
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,29 @@ | ||
import {type ClientPerspective} from '@sanity/client' | ||
import {type FC, memo, useEffect} from 'react' | ||
|
||
import {type VisualEditingConnection} from './types' | ||
|
||
export interface PostMessagePerspectiveProps { | ||
comlink: VisualEditingConnection | ||
perspective: ClientPerspective | ||
} | ||
|
||
const PostMessagePerspective: FC<PostMessagePerspectiveProps> = (props) => { | ||
const {comlink, perspective} = props | ||
|
||
// Return the perspective when requested | ||
useEffect(() => { | ||
return comlink.on('visual-editing/fetch-perspective', () => ({ | ||
perspective, | ||
})) | ||
}, [comlink, perspective]) | ||
|
||
// Dispatch a perspective message when the perspective changes | ||
useEffect(() => { | ||
comlink.post('presentation/perspective', {perspective}) | ||
}, [comlink, perspective]) | ||
|
||
return null | ||
} | ||
|
||
export default memo(PostMessagePerspective) |
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,27 @@ | ||
import {useTelemetry} from '@sanity/telemetry/react' | ||
import {type FC, memo, useEffect} from 'react' | ||
|
||
import {type VisualEditingConnection} from './types' | ||
|
||
export interface PostMessageTelemetryProps { | ||
comlink: VisualEditingConnection | ||
} | ||
|
||
const PostMessageTelemetry: FC<PostMessageTelemetryProps> = (props) => { | ||
const {comlink} = props | ||
|
||
const telemetry = useTelemetry() | ||
|
||
useEffect(() => { | ||
return comlink.on('visual-editing/telemetry-log', async (message) => { | ||
const {event, data} = message | ||
|
||
// SANITY_STUDIO_DEBUG_TELEMETRY ensures noop/in-browser logging for telemetry events | ||
// eslint-disable-next-line no-unused-expressions | ||
data ? telemetry.log(event, data) : telemetry.log(event) | ||
}) | ||
}, [comlink, telemetry]) | ||
|
||
return null | ||
} | ||
export default memo(PostMessageTelemetry) |
Oops, something went wrong.