Socket
Socket
Sign inDemoInstall

@sanity/presentation

Package Overview
Dependencies
Maintainers
44
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/presentation - npm Package Compare versions

Comparing version 1.5.3 to 1.6.0

dist/_chunks/index-gvCWCnr7.cjs

43

CHANGELOG.md
# Changelog
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @sanity/preview-url-secret bumped to 1.0.2
## [1.6.0](https://github.com/sanity-io/visual-editing/compare/presentation-v1.5.3...presentation-v1.6.0) (2024-01-16)
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @sanity/preview-url-secret bumped to 1.2.0
### Features
### Dependencies
* enable new URL sharing menu ([83fe01f](https://github.com/sanity-io/visual-editing/commit/83fe01fbe4ee3128a49401e2882e04463b5b1540))
* The following workspace dependencies were updated
* dependencies
* @sanity/groq-store bumped from 5.3.1 to 5.3.2
* devDependencies
* @sanity/visual-editing-helpers bumped from 0.1.0 to 0.1.1
### Dependencies
### Bug Fixes
* The following workspace dependencies were updated
* dependencies
* @sanity/groq-store bumped from 5.3.3 to 5.3.4
* devDependencies
* @sanity/visual-editing-helpers bumped from 0.1.2 to 0.1.3
* always use the same `@sanity/ui` version as `sanity` ([e61312d](https://github.com/sanity-io/visual-editing/commit/e61312d9a2d8ebcce8f0b06a62b0bcd5ca42522f))
* **presentation:** allow forward navigation ([#686](https://github.com/sanity-io/visual-editing/issues/686)) ([f9099e8](https://github.com/sanity-io/visual-editing/commit/f9099e88f5d3f4158fbe26737e0b1c6987df29f9))
* **presentation:** derive params from routerState to fix focus ([175efe0](https://github.com/sanity-io/visual-editing/commit/175efe0a3881c288c8ea30086e427a1de21c60cd))
* remove MetaBanner as it's now part of `sanity` ([c920188](https://github.com/sanity-io/visual-editing/commit/c920188859200770d31ff3e679e86563bcc4e52e))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @sanity/groq-store bumped from 5.3.5 to 5.3.6
* @sanity/preview-url-secret bumped from ^1.3.5 to ^1.3.6
* devDependencies
* @sanity/channels bumped from 0.2.0 to 0.3.0
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @sanity/preview-url-secret bumped from ^1.4.0 to ^1.4.1
## [1.5.3](https://github.com/sanity-io/visual-editing/compare/presentation-v1.5.2...presentation-v1.5.3) (2024-01-11)

@@ -47,0 +20,0 @@

@@ -73,2 +73,8 @@ /// <reference types="react" />

export declare type PresentationNavigate = (
nextState: PresentationStateParams,
nextSearchState?: PresentationSearchParams,
forceReplace?: boolean,
) => void
export declare type PresentationNavigateContextValue = (preview: string) => void

@@ -94,5 +100,14 @@

}
/**
* @deprecated this feature flag is no longer needed
*/
unstable_showUnsafeShareUrl?: boolean
}
export declare interface PresentationSearchParams
extends DeskDocumentPaneParams {
preview?: string
perspective?: string
}
export declare interface PresentationStateParams {

@@ -115,4 +130,2 @@ type?: string

export declare type SetPresentationParams = (prev: PresentationParams) => void
export declare function usePresentationNavigate(): PresentationNavigateContextValue

@@ -119,0 +132,0 @@

@@ -1,1 +0,1 @@

export{p as presentationTool,u as usePresentationNavigate,e as usePresentationParams}from"./_chunks/index-KysVgDho.js";//# sourceMappingURL=index.js.map
export{p as presentationTool,u as usePresentationNavigate,e as usePresentationParams}from"./_chunks/index-scF3Q7eu.js";//# sourceMappingURL=index.js.map
{
"name": "@sanity/presentation",
"version": "1.5.3",
"version": "1.6.0",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/presentation#readme",

@@ -110,3 +110,2 @@ "bugs": {

"@sanity/preview-url-secret": "^1.5.2",
"@sanity/ui": "2.0.0-beta.17",
"@types/lodash.isequal": "^4.5.8",

@@ -124,5 +123,6 @@ "fast-deep-equal": "3.1.3",

"@sanity/client": "^6.11.1",
"@sanity/pkg-utils": "^3.3.7",
"@sanity/pkg-utils": "^3.3.8",
"@sanity/ui": "2.0.0",
"@sanity/visual-editing-helpers": "0.2.3",
"happy-dom": "^13.0.0",
"happy-dom": "^13.1.4",
"react": "^18.2.0",

@@ -133,3 +133,3 @@ "react-dom": "^18.2.0",

"typescript": "^5.3.3",
"vitest": "^1.1.3"
"vitest": "^1.2.0"
},

@@ -136,0 +136,0 @@ "peerDependencies": {

@@ -5,4 +5,4 @@ import { createContext } from 'react'

DeskDocumentPaneParams,
PresentationNavigate,
PresentationParams,
SetPresentationParams,
} from './types'

@@ -14,4 +14,4 @@

name: string
navigate: PresentationNavigate
params: PresentationParams
setParams: SetPresentationParams
}

@@ -18,0 +18,0 @@

@@ -53,2 +53,5 @@ import type { ClientPerspective, QueryParams } from '@sanity/client'

}
/**
* @deprecated this feature flag is no longer needed
*/
unstable_showUnsafeShareUrl?: boolean

@@ -87,4 +90,13 @@ }

export type SetPresentationParams = (prev: PresentationParams) => void
export interface PresentationSearchParams extends DeskDocumentPaneParams {
preview?: string
perspective?: string
}
export type PresentationNavigate = (
nextState: PresentationStateParams,
nextSearchState?: PresentationSearchParams,
forceReplace?: boolean,
) => void
/** @internal */

@@ -91,0 +103,0 @@ export type LiveQueriesState = Record<string, LiveQueriesStateValue>

@@ -1,6 +0,3 @@

import { studioPath } from '@sanity/client/csm'
import { pathToUrlString } from '@sanity/visual-editing-helpers'
import isEqual from 'lodash.isequal'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { NavigateOptions, RouterContextValue, RouterState } from 'sanity/router'
import { MutableRefObject, useEffect, useMemo, useRef } from 'react'
import { RouterContextValue, RouterState, SearchParam } from 'sanity/router'

@@ -11,5 +8,6 @@ import { debounce } from './lib/debounce'

DeskDocumentPaneParams,
PresentationNavigate,
PresentationParams,
PresentationSearchParams,
PresentationStateParams,
SetPresentationParams,
} from './types'

@@ -30,16 +28,17 @@

routerSearchParams,
previewRef,
}: {
initialPreviewUrl: URL
routerNavigate: RouterContextValue['navigate']
routerState: PresentationStateParams
routerState: RouterState & PresentationStateParams
routerSearchParams: {
[k: string]: string
}
previewRef: MutableRefObject<string | undefined>
}): {
deskParams: DeskDocumentPaneParams
navigate: (nextState: RouterState, options?: NavigateOptions) => void
navigate: PresentationNavigate
params: PresentationParams
setParams: SetPresentationParams
} {
const [params, setParamsState] = useState<PresentationParams>(() => {
const params = useMemo<PresentationParams>(() => {
const { id, path, type } = parseRouterState(routerState)

@@ -66,95 +65,8 @@

}
})
}, [routerState, routerSearchParams, initialPreviewUrl])
const setParams = useCallback((newParams: Partial<PresentationParams>) => {
setParamsState((state) => {
const nextState = { ...state, ...newParams }
if (isEqual(pruneObject(state), pruneObject(nextState))) {
return state
}
return nextState
})
}, [])
const deskParams = useMemo<DeskDocumentPaneParams>(
() =>
pruneObject({
inspect: params.inspect,
path: params.path,
rev: params.rev,
since: params.since,
template: params.template,
view: params.view,
// assist
pathKey: params.pathKey,
instruction: params.instruction,
// comments
comment: params.comment,
}),
[
params.inspect,
params.path,
params.rev,
params.since,
params.template,
params.view,
params.pathKey,
params.instruction,
params.comment,
],
)
useEffect(() => {
const { id, path, type } = parseRouterState(routerState)
const timeout = setTimeout(
() =>
setParams({
id,
type: type === '*' ? undefined : type,
path,
preview:
routerSearchParams.preview ||
`${initialPreviewUrl.pathname}${initialPreviewUrl.search}`,
perspective: routerSearchParams.perspective,
inspect: routerSearchParams.inspect,
rev: routerSearchParams.rev,
since: routerSearchParams.since,
template: routerSearchParams.template,
view: routerSearchParams.view,
// assist
pathKey: routerSearchParams.pathKey,
instruction: routerSearchParams.instruction,
// comments
comment: routerSearchParams.comment,
}),
0,
)
return () => clearTimeout(timeout)
}, [initialPreviewUrl, routerSearchParams, routerState, setParams])
const navigate = useMemo(() => {
// Debounce navigation to mitigate various event related race conditions
return debounce((nextState: RouterState, options?: NavigateOptions) => {
const state = pruneObject(nextState)
routerNavigate(state, options)
}, 50)
}, [routerNavigate])
const previewRef = useRef(params.preview)
useEffect(() => {
const previousPreview = previewRef.current
previewRef.current = params.preview
const type = params.type
const id = params.id
const path = params.path
? pathToUrlString(studioPath.fromString(params.path))
: undefined
const searchParams = pruneObject({
preview: params.preview,
perspective: params.perspective === 'published' ? 'published' : undefined,
const deskParams = useMemo<DeskDocumentPaneParams>(() => {
const pruned = pruneObject({
inspect: params.inspect,
path: params.path,
rev: params.rev,

@@ -169,29 +81,70 @@ since: params.since,

comment: params.comment,
}) satisfies PresentationParams
})
return pruned
}, [
params.inspect,
params.path,
params.rev,
params.since,
params.template,
params.view,
params.pathKey,
params.instruction,
params.comment,
])
const replace = params.preview === previousPreview
const timeout = setTimeout(
() =>
navigate(
{
type,
id,
path,
_searchParams: Object.entries(
searchParams as Record<string, string>,
const routerStateRef = useRef(routerState)
useEffect(() => {
routerStateRef.current = routerState
}, [routerState])
const navigate = useMemo(
() =>
debounce<PresentationNavigate>(
(nextState, nextSearchState = {}, forceReplace) => {
// Extract type, id and path as 'routerState'
const { _searchParams: routerSearchParams, ...routerState } =
routerStateRef.current
// Convert array of search params to an object
const routerSearchState = (routerSearchParams || []).reduce(
(acc, [key, value]) => (
(acc[key as keyof PresentationSearchParams] = value), acc
),
},
{ replace },
),
0,
)
return () => clearTimeout(timeout)
}, [navigate, params])
{} as PresentationSearchParams,
)
// Merge routerState and incoming state
const state: RouterState = pruneObject({
...routerState,
...nextState,
})
// Merge routerSearchState and incoming searchState
const searchState = pruneObject({
...routerSearchState,
...nextSearchState,
})
state._searchParams = Object.entries(searchState).reduce(
(acc, [key, value]) => [...acc, [key, value]],
[] as SearchParam[],
)
const replace =
forceReplace ?? searchState.preview === previewRef.current
routerNavigate(state, { replace })
},
50,
),
[routerNavigate, previewRef],
)
return {
deskParams,
navigate,
setParams,
deskParams,
params,
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc