Skip to content

Commit

Permalink
refactor: migrate @sanity/presentation codebase (#8312)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Jan 17, 2025
1 parent d4175f9 commit 680930c
Show file tree
Hide file tree
Showing 103 changed files with 11,632 additions and 73 deletions.
29 changes: 2 additions & 27 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,5 @@
/packages/@sanity/cli/src/commands/typegen @sanity-io/content-lake-dx
/packages/@sanity/cli/src/workers/typegenGenerate.ts @sanity-io/content-lake-dx

# Internals used by @sanity/presentation
# See https://github.com/sanity-io/visual-editing/blob/main/packages/presentation/src/internals.ts for exactly which exports
/packages/sanity/src/_singletons/structure/components/paneRouter/PaneRouterContext.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/comments/context/intent/CommentsIntentProvider.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/comments/types.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/config/document/fieldActions/define.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/config/document/fieldActions/types.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/field/paths/helpers.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/hooks/useEditState.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/preview/components/Preview.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/store/_legacy/datastores.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/store/_legacy/document/document-store.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/studio/activeWorkspaceMatcher/useActiveWorkspace.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/studio/workspace.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/util/draftUtils.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/util/isRecord.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/core/util/useUnique.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/router/utils/jsonParamsEncoding.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/components/pane/PaneLayout.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/components/paneRouter/types.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/panes/document/DocumentPane.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/panes/document/useDocumentPane.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/panes/documentList/index.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/panes/documentList/pane.ts @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/panes/documentList/PaneContainer.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/StructureToolProvider.tsx @sanity-io/ecosystem @sanity-io/studio
/packages/sanity/src/structure/types.ts @sanity-io/ecosystem @sanity-io/studio
# Presentation Tool, which interfaces with Visual Editing libraries
/packages/sanity/src/presentation/ @sanity-io/ecosystem
10 changes: 8 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@
"@portabletext/editor",
"@sanity/bifur-client",
"@sanity/client",
"@sanity/comlink",
"@sanity/export",
"@sanity/icons",
"@sanity/insert-menu",
"@sanity/mutate",
"@sanity/presentation",
"@sanity/presentation-comlink",
"@sanity/preview-url-secret",
"@sanity/template-validator",
"@sanity/ui",
"@sanity/visual-editing-csm",
"get-it",
"groq-js",
"react-rx"
Expand All @@ -67,16 +70,19 @@
"@portabletext/editor",
"@sanity/bifur-client",
"@sanity/client",
"@sanity/comlink",
"@sanity/eslint-config-i18n",
"@sanity/export",
"@sanity/icons",
"@sanity/insert-menu",
"@sanity/mutate",
"@sanity/pkg-utils",
"@sanity/presentation",
"@sanity/presentation-comlink",
"@sanity/preview-url-secret",
"@sanity/template-validator",
"@sanity/tsdoc",
"@sanity/ui",
"@sanity/visual-editing-csm",
"esbuild",
"get-it",
"groq-js",
Expand Down
4 changes: 4 additions & 0 deletions packages/sanity/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ module.exports = {
name: 'sanity',
message: 'Use relative type imports instead',
},
{
name: 'sanity/presentation',
message: 'Use relative type imports instead',
},
{
name: 'sanity/structure',
message: 'Use relative type imports instead',
Expand Down
6 changes: 6 additions & 0 deletions packages/sanity/package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import {defineConfig} from '@sanity/pkg-utils'
export default defineConfig({
...baseConfig,

define: {
...baseConfig.define,
PRESENTATION_ENABLE_LIVE_DRAFT_EVENTS:
process.env.PRESENTATION_ENABLE_LIVE_DRAFT_EVENTS === 'true',
},

// Build unexposed bundles for scripts that need to be spawned/used in workers
bundles: [
{
Expand Down
15 changes: 12 additions & 3 deletions packages/sanity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"@sanity/cli": "3.70.0",
"@sanity/client": "^6.25.0",
"@sanity/color": "^3.0.0",
"@sanity/comlink": "^3.0.1",
"@sanity/diff": "3.70.0",
"@sanity/diff-match-patch": "^3.1.1",
"@sanity/eventsource": "^5.0.0",
Expand All @@ -170,16 +171,17 @@
"@sanity/image-url": "^1.0.2",
"@sanity/import": "^3.37.9",
"@sanity/insert-menu": "1.0.19",
"@sanity/logos": "^2.1.4",
"@sanity/logos": "^2.1.13",
"@sanity/migrate": "3.70.0",
"@sanity/mutator": "3.70.0",
"@sanity/presentation": "1.22.1",
"@sanity/presentation-comlink": "^1.0.0",
"@sanity/preview-url-secret": "^2.0.0",
"@sanity/schema": "3.70.0",
"@sanity/telemetry": "^0.7.7",
"@sanity/types": "3.70.0",
"@sanity/ui": "^2.11.2",
"@sanity/util": "3.70.0",
"@sanity/uuid": "^3.0.1",
"@sanity/uuid": "^3.0.2",
"@sentry/react": "^8.33.0",
"@tanstack/react-table": "^8.16.0",
"@tanstack/react-virtual": "^3.11.2",
Expand All @@ -205,6 +207,7 @@
"esbuild-register": "^3.5.0",
"execa": "^2.0.0",
"exif-component": "^1.0.1",
"fast-deep-equal": "3.1.3",
"form-data": "^4.0.0",
"framer-motion": "^11.15.0",
"get-it": "^8.6.6",
Expand All @@ -223,6 +226,7 @@
"lodash": "^4.17.21",
"log-symbols": "^2.2.0",
"mendoza": "^3.0.0",
"mnemonist": "0.39.8",
"module-alias": "^2.2.2",
"nano-pubsub": "^3.0.0",
"nanoid": "^3.1.30",
Expand All @@ -231,6 +235,7 @@
"oneline": "^1.0.3",
"open": "^8.4.0",
"p-map": "^7.0.0",
"path-to-regexp": "^6.3.0",
"pirates": "^4.0.0",
"pluralize-esm": "^9.0.2",
"polished": "^4.2.2",
Expand All @@ -256,12 +261,15 @@
"semver": "^7.3.5",
"shallow-equals": "^1.0.0",
"speakingurl": "^14.0.1",
"suspend-react": "0.1.3",
"tar-fs": "^2.1.1",
"tar-stream": "^3.1.7",
"use-device-pixel-ratio": "^1.1.0",
"use-effect-event": "^1.0.2",
"use-hot-module-reload": "^2.0.0",
"use-sync-external-store": "^1.2.0",
"uuid": "^11.0.5",
"valibot": "0.31.1",
"vite": "^6.0.7",
"yargs": "^17.3.0"
},
Expand All @@ -276,6 +284,7 @@
"@sanity/pkg-utils": "6.13.4",
"@sanity/tsdoc": "1.0.169",
"@sanity/ui-workshop": "^1.2.11",
"@sanity/visual-editing-csm": "^1.0.0",
"@sentry/types": "^8.12.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/_exports/presentation.ts
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 packages/sanity/src/_singletons/context/PresentationContext.ts
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,
)
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,
)
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,
)
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,
)
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,
)
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,
)
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,
)
7 changes: 7 additions & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export * from './context/PortableTextMemberItemElementRefsContext'
export * from './context/PortableTextMemberItemsContext'
export * from './context/PresenceContext'
export * from './context/PresenceTrackerContexts'
export * from './context/PresentationContext'
export * from './context/PresentationDisplayedDocumentContext'
export * from './context/PresentationDocumentContext'
export * from './context/PresentationNavigateContext'
export * from './context/PresentationPanelsContext'
export * from './context/PresentationParamsContext'
export * from './context/PresentationSharedStateContext'
export * from './context/PreviewCardContext'
export * from './context/ReferenceInputOptionsContext'
export * from './context/ReferenceItemRefContext'
Expand Down
29 changes: 29 additions & 0 deletions packages/sanity/src/presentation/PostMessagePerspective.tsx
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)
27 changes: 27 additions & 0 deletions packages/sanity/src/presentation/PostMessageTelemetry.tsx
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)
Loading

0 comments on commit 680930c

Please sign in to comment.