@sanity/presentation
Advanced tools
Comparing version 1.5.3 to 1.6.0
# 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
11
797304
12
81
6015
- Removed@sanity/ui@2.0.0-beta.17
- Removed@emotion/is-prop-valid@1.2.2(transitive)
- Removed@emotion/memoize@0.8.1(transitive)
- Removed@emotion/unitless@0.8.1(transitive)
- Removed@floating-ui/core@1.6.8(transitive)
- Removed@floating-ui/dom@1.6.11(transitive)
- Removed@floating-ui/react-dom@2.1.2(transitive)
- Removed@floating-ui/utils@0.2.8(transitive)
- Removed@sanity/color@3.0.0-beta.9(transitive)
- Removed@sanity/ui@2.0.0-beta.17(transitive)
- Removed@types/hast@2.3.10(transitive)
- Removed@types/stylis@4.2.5(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removedcamelize@1.0.1(transitive)
- Removedcharacter-entities@1.2.4(transitive)
- Removedcharacter-entities-legacy@1.1.4(transitive)
- Removedcharacter-reference-invalid@1.1.4(transitive)
- Removedcomma-separated-tokens@1.0.8(transitive)
- Removedcss-color-keywords@1.0.0(transitive)
- Removedcss-to-react-native@3.2.0(transitive)
- Removedcsstype@3.1.3(transitive)
- Removedhast-util-parse-selector@2.2.5(transitive)
- Removedhastscript@6.0.0(transitive)
- Removedis-alphabetical@1.0.4(transitive)
- Removedis-alphanumerical@1.0.4(transitive)
- Removedis-decimal@1.0.4(transitive)
- Removedis-hexadecimal@1.0.4(transitive)
- Removednanoid@3.3.7(transitive)
- Removedparse-entities@2.0.0(transitive)
- Removedpicocolors@1.1.0(transitive)
- Removedpostcss@8.4.38(transitive)
- Removedpostcss-value-parser@4.2.0(transitive)
- Removedprismjs@1.27.0(transitive)
- Removedproperty-information@5.6.0(transitive)
- Removedreact-dom@18.3.1(transitive)
- Removedreact-is@18.3.1(transitive)
- Removedreact-refractor@2.2.0(transitive)
- Removedrefractor@3.6.0(transitive)
- Removedscheduler@0.23.2(transitive)
- Removedshallowequal@1.1.0(transitive)
- Removedsource-map-js@1.2.1(transitive)
- Removedspace-separated-tokens@1.1.5(transitive)
- Removedstyled-components@6.1.13(transitive)
- Removedstylis@4.3.2(transitive)
- Removedtslib@2.6.2(transitive)
- Removedunist-util-filter@2.0.3(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)