Socket
Socket
Sign inDemoInstall

@sanity/presentation

Package Overview
Dependencies
89
Maintainers
48
Versions
127
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.12.5 to 1.12.6

25

dist/index.d.ts
/// <reference types="react" />
import type { ClientPerspective } from '@sanity/client'
import type { ComponentType } from 'react'
import type { DocumentStore } from 'sanity'
import type { Observable } from 'rxjs'
import { Plugin as Plugin_2 } from 'sanity'
import type { PreviewUrlResolver } from '@sanity/preview-url-secret/define-preview-url'
import type { PreviewUrlResolverOptions } from '@sanity/preview-url-secret/define-preview-url'
import type { QueryParams } from '@sanity/client'
import type { SanityClient } from 'sanity'
import type {ClientPerspective} from '@sanity/client'
import type {ComponentType} from 'react'
import type {DocumentStore} from 'sanity'
import type {Observable} from 'rxjs'
import {Plugin as Plugin_2} from 'sanity'
import type {PreviewUrlResolver} from '@sanity/preview-url-secret/define-preview-url'
import type {PreviewUrlResolverOptions} from '@sanity/preview-url-secret/define-preview-url'
import type {QueryParams} from '@sanity/client'
import type {SanityClient} from 'sanity'

@@ -106,4 +106,3 @@ export declare interface DocumentLocation {

export declare interface PresentationSearchParams
extends StructureDocumentPaneParams {
export declare interface PresentationSearchParams extends StructureDocumentPaneParams {
preview?: string

@@ -127,5 +126,5 @@ perspective?: string

export { PreviewUrlResolver }
export {PreviewUrlResolver}
export { PreviewUrlResolverOptions }
export {PreviewUrlResolverOptions}

@@ -132,0 +131,0 @@ export declare interface StructureDocumentPaneParams {

{
"name": "@sanity/presentation",
"version": "1.12.5",
"version": "1.12.6",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/presentation#readme",

@@ -35,9 +35,3 @@ "bugs": {

"browserslist": "extends @sanity/browserslist-config",
"prettier": {
"plugins": [
"prettier-plugin-packagejson"
],
"semi": false,
"singleQuote": true
},
"prettier": "@sanity/prettier-config",
"eslintConfig": {

@@ -101,4 +95,4 @@ "parser": "@typescript-eslint/parser",

"@sanity/icons": "^2.11.8",
"@sanity/preview-url-secret": "^1.6.9",
"@sanity/ui": "^2.1.3",
"@sanity/preview-url-secret": "^1.6.10",
"@sanity/ui": "^2.1.4",
"@sanity/uuid": "3.0.2",

@@ -116,5 +110,5 @@ "@types/lodash.isequal": "^4.5.8",

"@repo/channels": "0.4.0",
"@repo/visual-editing-helpers": "0.6.6",
"@sanity/client": "^6.15.17",
"@sanity/pkg-utils": "6.7.0",
"@repo/visual-editing-helpers": "0.6.7",
"@sanity/client": "^6.15.19",
"@sanity/pkg-utils": "6.8.1",
"happy-dom": "^14.7.1",

@@ -130,3 +124,3 @@ "react": "^18.2.0",

"peerDependencies": {
"@sanity/client": "^6.15.17"
"@sanity/client": "^6.15.19"
},

@@ -133,0 +127,0 @@ "engines": {

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

import { ComposeIcon } from '@sanity/icons'
import {ComposeIcon} from '@sanity/icons'

@@ -3,0 +3,0 @@ export const DEFAULT_TOOL_ICON = ComposeIcon

@@ -1,6 +0,7 @@

import { createContext } from 'react'
import {createContext} from 'react'
import { PresentationDocumentContextValue } from './types'
import type {PresentationDocumentContextValue} from './types'
export const PresentationDocumentContext =
createContext<PresentationDocumentContextValue | null>(null)
export const PresentationDocumentContext = createContext<PresentationDocumentContextValue | null>(
null,
)

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

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

@@ -3,0 +3,0 @@ export interface PresentationDocumentContextValue {

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

import { MasterDetailIcon } from '@sanity/icons'
import { useContext, useMemo } from 'react'
import {MasterDetailIcon} from '@sanity/icons'
import {useContext, useMemo} from 'react'
import {
defineDocumentFieldAction,
DocumentFieldActionItem,
type DocumentFieldActionItem,
isRecord,
pathToString,
Tool,
type Tool,
useWorkspace,
} from 'sanity'
import { useRouter } from 'sanity/router'
import {useRouter} from 'sanity/router'
import { PresentationContext } from '../PresentationContext'
import {PresentationContext} from '../PresentationContext'
export const openInStructure = defineDocumentFieldAction({
name: 'presentation/openInStructure',
useAction({ documentId, documentType, path }) {
useAction({documentId, documentType, path}) {
const workspace = useWorkspace()
const { navigateIntent } = useRouter()
const {navigateIntent} = useRouter()
const presentation = useContext(PresentationContext)

@@ -61,6 +61,6 @@

return { tool: t, match }
return {tool: t, match}
})
const modeMatches = results.filter((t) => isRecord(t.match) && t.match.mode)
const modeMatches = results.filter((t) => isRecord(t.match) && t.match['mode'])

@@ -67,0 +67,0 @@ if (modeMatches.length > 0) {

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

import { uuid } from '@sanity/uuid'
import { getPublishedId } from 'sanity'
import { encodeJsonParams, SearchParam } from 'sanity/router'
import {uuid} from '@sanity/uuid'
import {getPublishedId} from 'sanity'
import {encodeJsonParams, type SearchParam} from 'sanity/router'
import { PresentationStateParams } from './types'
import type {PresentationStateParams} from './types'

@@ -16,6 +16,6 @@ /**

):
| (PresentationStateParams & { _searchParams: SearchParam[] })
| { intent: string; params: Record<string, string>; payload: unknown } {
| (PresentationStateParams & {_searchParams: SearchParam[]})
| {intent: string; params: Record<string, string>; payload: unknown} {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id, mode, path, presentation, type, ...searchParams } = params
const {id, mode, path, presentation, type, ...searchParams} = params

@@ -32,11 +32,7 @@ if (intent === 'edit' && id) {

if (intent === 'create') {
searchParams.preview =
searchParams.preview ||
new URLSearchParams(window.location.search).get('preview') ||
'/'
searchParams['preview'] =
searchParams['preview'] || new URLSearchParams(window.location.search).get('preview') || '/'
if (payload && typeof payload === 'object') {
searchParams.templateParams = encodeJsonParams(
payload as Record<string, unknown>,
)
searchParams['templateParams'] = encodeJsonParams(payload as Record<string, unknown>)
}

@@ -50,3 +46,3 @@

}
return { intent, params, payload }
return {intent, params, payload}
}

@@ -7,2 +7,2 @@ export * from './plugin'

} from './usePresentationNavigate'
export { usePresentationParams } from './usePresentationParams'
export {usePresentationParams} from './usePresentationParams'

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

import { urlStringToPath } from '@repo/visual-editing-helpers'
import { studioPath } from '@sanity/client/csm'
import {urlStringToPath} from '@repo/visual-editing-helpers'
import {studioPath} from '@sanity/client/csm'
import type { PresentationStateParams } from '../types'
import type {PresentationStateParams} from '../types'

@@ -28,5 +28,3 @@ export function parseId(rawId: string | undefined): string | undefined {

export function parseRouterState(
state: PresentationStateParams,
): PresentationStateParams {
export function parseRouterState(state: PresentationStateParams): PresentationStateParams {
return {

@@ -33,0 +31,0 @@ id: parseId(state.id),

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

import type { ContentSourceMap } from '@sanity/client'
import type {ContentSourceMap} from '@sanity/client'
import LRUCache from 'mnemonist/lru-cache-with-delete'
import type { SanityDocument } from 'sanity'
import { expect, test } from 'vitest'
import type {SanityDocument} from 'sanity'
import {expect, test} from 'vitest'
import { LIVE_QUERY_CACHE_SIZE } from '../constants'
import { turboChargeResultIfSourceMap } from './LoaderQueries'
import {LIVE_QUERY_CACHE_SIZE} from '../constants'
import {turboChargeResultIfSourceMap} from './LoaderQueries'

@@ -24,4 +24,3 @@ const perspective = 'previewDrafts'

headline: 'Touch of Texture ',
subline:
'You can follow us on Twitter, Twitch, LinkedIn, and GitHub.',
subline: 'You can follow us on Twitter, Twitch, LinkedIn, and GitHub.',
style: {

@@ -40,4 +39,3 @@ _type: 'sectionStyle',

_key: '50692538e3551f1805206202c8838ea5',
subline:
'You can follow us on Twitter, Twitch, LinkedIn, and GitHub..',
subline: 'You can follow us on Twitter, Twitch, LinkedIn, and GitHub..',
symbol: null,

@@ -833,5 +831,3 @@ tagline: 'ACME’s elegant construction is both minimal and inviting.',

expect(result.page.sections[0].headline).not.toBe(draft.sections[0].headline)
expect(turboCharged.page.sections[0].headline).toBe(
draft.sections[0].headline,
)
expect(turboCharged.page.sections[0].headline).toBe(draft.sections[0].headline)
})

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

import type { ClientPerspective, QueryParams } from '@sanity/client'
import type {ClientPerspective, QueryParams} from '@sanity/client'

@@ -3,0 +3,0 @@ /**

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

import { RefObject } from 'react'
import type {RefObject} from 'react'

@@ -3,0 +3,0 @@ export interface PanelElement {

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

import { useRef } from 'react'
import { v4 as uuid } from 'uuid'
import {useRef} from 'react'
import {v4 as uuid} from 'uuid'

@@ -4,0 +4,0 @@ export function usePanelId(id?: string): string {

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

import { useMemo } from 'react'
import {useMemo} from 'react'
import { debounce } from '../lib/debounce'
import { PanelElement } from './types'
import {debounce} from '../lib/debounce'
import type {PanelElement} from './types'

@@ -6,0 +6,0 @@ const itemKey = 'presentation/panels'

@@ -1,17 +0,6 @@

import {
ElementMap,
InitialDragState,
PanelElement,
PanelsState,
ResizerElement,
} from './types'
import type {ElementMap, InitialDragState, PanelElement, PanelsState, ResizerElement} from './types'
function getNextWidth(
panel: PanelElement,
nextWidth: number,
containerWidth: number,
) {
const { maxWidth: maxWidthPx, minWidth: minWidthPx } = panel
const maxWidth =
maxWidthPx == null ? 100 : (maxWidthPx / containerWidth) * 100
function getNextWidth(panel: PanelElement, nextWidth: number, containerWidth: number) {
const {maxWidth: maxWidthPx, minWidth: minWidthPx} = panel
const maxWidth = maxWidthPx == null ? 100 : (maxWidthPx / containerWidth) * 100
const minWidth = (minWidthPx / containerWidth) * 100

@@ -29,4 +18,4 @@ return Math.min(maxWidth, Math.max(minWidth, nextWidth))

): number[] {
const { panels, widths: prevWidths } = panelsState
const { widths: initialWidths } = initialDragState
const {panels, widths: prevWidths} = panelsState
const {widths: initialWidths} = initialDragState

@@ -40,7 +29,3 @@ const widths = initialWidths || prevWidths

const width = widths[index]
const nextWidth = getNextWidth(
pivotPanel,
width + Math.abs(delta),
containerWidth,
)
const nextWidth = getNextWidth(pivotPanel, width + Math.abs(delta), containerWidth)
if (width === nextWidth) {

@@ -64,7 +49,3 @@ return widths

const nextWidth = getNextWidth(
panel,
width - deltaRemaining,
containerWidth,
)
const nextWidth = getNextWidth(panel, width - deltaRemaining, containerWidth)

@@ -76,7 +57,5 @@ if (width !== nextWidth) {

if (
deltaApplied
.toPrecision(10)
.localeCompare(Math.abs(delta).toPrecision(10), undefined, {
numeric: true,
}) >= 0
deltaApplied.toPrecision(10).localeCompare(Math.abs(delta).toPrecision(10), undefined, {
numeric: true,
}) >= 0
) {

@@ -109,7 +88,3 @@ break

export function getPanelWidth(
panels: PanelElement[],
id: string,
widths: number[],
): string {
export function getPanelWidth(panels: PanelElement[], id: string, widths: number[]): string {
if (panels.length === 1) return '100'

@@ -139,18 +114,12 @@

export function isPanel(
element: PanelElement | ResizerElement,
): element is PanelElement {
export function isPanel(element: PanelElement | ResizerElement): element is PanelElement {
return element.type === 'panel'
}
export function isResizer(
element: PanelElement | ResizerElement,
): element is ResizerElement {
export function isResizer(element: PanelElement | ResizerElement): element is ResizerElement {
return element.type === 'resizer'
}
export function getSortedElements(
elements: ElementMap,
): Array<PanelElement | ResizerElement> {
return Array.from(elements.values()).sort(({ order: a }, { order: b }) => {
export function getSortedElements(elements: ElementMap): Array<PanelElement | ResizerElement> {
return Array.from(elements.values()).sort(({order: a}, {order: b}) => {
if (a == null && b == null) return 0

@@ -188,3 +157,3 @@ if (a == null) return -1

let { maxWidth, minWidth } = panel
let {maxWidth, minWidth} = panel

@@ -191,0 +160,0 @@ minWidth = (minWidth / containerWidth) * 100

@@ -1,8 +0,4 @@

import { createContext } from 'react'
import {createContext} from 'react'
import {
PresentationNavigate,
PresentationParams,
StructureDocumentPaneParams,
} from './types'
import type {PresentationNavigate, PresentationParams, StructureDocumentPaneParams} from './types'

@@ -17,3 +13,2 @@ export interface PresentationContextValue {

export const PresentationContext =
createContext<PresentationContextValue | null>(null)
export const PresentationContext = createContext<PresentationContextValue | null>(null)

@@ -1,9 +0,10 @@

import { createContext } from 'react'
import {createContext} from 'react'
export type PresentationNavigateContextValue = (
preview: string | undefined,
document?: { type: string; id: string },
document?: {type: string; id: string},
) => void
export const PresentationNavigateContext =
createContext<PresentationNavigateContextValue | null>(null)
export const PresentationNavigateContext = createContext<PresentationNavigateContextValue | null>(
null,
)

@@ -1,6 +0,5 @@

import { createContext } from 'react'
import {createContext} from 'react'
import { PresentationParams } from './types'
import type {PresentationParams} from './types'
export const PresentationParamsContext =
createContext<PresentationParams | null>(null)
export const PresentationParamsContext = createContext<PresentationParams | null>(null)

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

import type { ClientPerspective } from '@sanity/client'
import type { Dispatch, Reducer } from 'react'
import { boolean, fallback, object, parse, picklist } from 'valibot'
import type {ClientPerspective} from '@sanity/client'
import type {Dispatch, Reducer} from 'react'
import {boolean, fallback, object, parse, picklist} from 'valibot'

@@ -27,4 +27,3 @@ export interface PresentationState {

export const ACTION_VIEWPORT = 'ACTION_VIEWPORT'
export const ACTION_VISUAL_EDITING_OVERLAYS_TOGGLE =
'ACTION_VISUAL_EDITING_OVERLAYS_TOGGLE'
export const ACTION_VISUAL_EDITING_OVERLAYS_TOGGLE = 'ACTION_VISUAL_EDITING_OVERLAYS_TOGGLE'

@@ -127,13 +126,5 @@ interface IframeLoadedAction {

const iframeStatusSchema = picklist([
'loading',
'loaded',
'refreshing',
'reloading',
])
const iframeStatusSchema = picklist(['loading', 'loaded', 'refreshing', 'reloading'])
const perspectiveSchema = fallback(
picklist([
'published',
'previewDrafts',
] satisfies PresentationState['perspective'][]),
picklist(['published', 'previewDrafts'] satisfies PresentationState['perspective'][]),
'previewDrafts',

@@ -151,3 +142,3 @@ )

viewport: viewportSchema,
visualEditing: object({ overlaysEnabled: boolean() }),
visualEditing: object({overlaysEnabled: boolean()}),
})

@@ -173,5 +164,5 @@

): Readonly<PresentationState> {
return parse(initStateSchema, { ...INITIAL_PRESENTATION_STATE, ...state })
return parse(initStateSchema, {...INITIAL_PRESENTATION_STATE, ...state})
}
export type DispatchPresentationAction = Dispatch<Readonly<PresentationAction>>

@@ -1,10 +0,6 @@

import { route } from 'sanity/router'
import {route} from 'sanity/router'
export const router = route.create(
'/',
{ __unsafe_disableScopedSearchParams: true },
[
route.intents('/intent'),
route.create(':type', [route.create(':id', [route.create(':path')])]),
],
)
export const router = route.create('/', {__unsafe_disableScopedSearchParams: true}, [
route.intents('/intent'),
route.create(':type', [route.create(':id', [route.create(':path')])]),
])

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

import type { ClientPerspective, QueryParams } from '@sanity/client'
import type {ClientPerspective, QueryParams} from '@sanity/client'
import type {

@@ -6,7 +6,7 @@ PreviewUrlResolver,

} from '@sanity/preview-url-secret/define-preview-url'
import type { ComponentType } from 'react'
import type { Observable } from 'rxjs'
import type { DocumentStore, SanityClient } from 'sanity'
import type {ComponentType} from 'react'
import type {Observable} from 'rxjs'
import type {DocumentStore, SanityClient} from 'sanity'
export type { PreviewUrlResolver, PreviewUrlResolverOptions }
export type {PreviewUrlResolver, PreviewUrlResolverOptions}

@@ -25,4 +25,4 @@ export interface DocumentLocation {

export type DocumentLocationResolver = (
params: { id: string; type: string },
context: { documentStore: DocumentStore },
params: {id: string; type: string},
context: {documentStore: DocumentStore},
) =>

@@ -40,6 +40,3 @@ | DocumentLocationsState

export type PreviewUrlOption =
| string
| PreviewUrlResolver<SanityClient>
| PreviewUrlResolverOptions
export type PreviewUrlOption = string | PreviewUrlResolver<SanityClient> | PreviewUrlResolverOptions

@@ -85,5 +82,3 @@ export interface PresentationPluginOptions {

export interface PresentationParams
extends PresentationStateParams,
StructureDocumentPaneParams {
export interface PresentationParams extends PresentationStateParams, StructureDocumentPaneParams {
id?: string

@@ -90,0 +85,0 @@ preview?: string

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

import { useEffect, useState } from 'react'
import { isObservable, of } from 'rxjs'
import { useDocumentStore } from 'sanity'
import {useEffect, useState} from 'react'
import {isObservable, of} from 'rxjs'
import {useDocumentStore} from 'sanity'
import { DocumentLocationResolver, DocumentLocationsState } from './types'
import type {DocumentLocationResolver, DocumentLocationsState} from './types'
const INITIAL_STATE: DocumentLocationsState = { locations: [] }
const INITIAL_STATE: DocumentLocationsState = {locations: []}

@@ -14,3 +14,3 @@ export function useDocumentLocations(props: {

}): DocumentLocationsState {
const { id, locate, type } = props
const {id, locate, type} = props
const documentStore = useDocumentStore()

@@ -22,4 +22,4 @@ const [state, setLocations] = useState<DocumentLocationsState>(INITIAL_STATE)

const params = { id, type }
const context = { documentStore }
const params = {id, type}
const context = {documentStore}

@@ -26,0 +26,0 @@ const result = locate(params, context)

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

import type { ClientPerspective } from '@sanity/client'
import type {ClientPerspective} from '@sanity/client'
import isEqual from 'fast-deep-equal'
import { MutableRefObject, useCallback, useMemo, useRef, useState } from 'react'
import {type MutableRefObject, useCallback, useMemo, useRef, useState} from 'react'
import type { PresentationState } from './reducers/presentationReducer'
import type { FrameState } from './types'
import type {PresentationState} from './reducers/presentationReducer'
import type {FrameState} from './types'

@@ -23,7 +23,3 @@ export type DocumentOnPage = {

DocumentOnPage[],
(
key: string,
perspective: PresentationState['perspective'],
state: DocumentOnPage[],
) => void,
(key: string, perspective: PresentationState['perspective'], state: DocumentOnPage[]) => void,
] {

@@ -42,7 +38,3 @@ if (perspective !== 'published' && perspective !== 'previewDrafts') {

const setDocumentsOnPage = useCallback(
(
key: string,
perspective: ClientPerspective,
sourceDocuments: DocumentOnPage[] = [],
) => {
(key: string, perspective: ClientPerspective, sourceDocuments: DocumentOnPage[] = []) => {
const documents = sourceDocuments.filter((sourceDocument) => {

@@ -64,4 +56,3 @@ if ('_projectId' in sourceDocument && sourceDocument._projectId) {

const setCache =
perspective === 'published' ? setPublished : setPreviewDrafts
const setCache = perspective === 'published' ? setPublished : setPreviewDrafts

@@ -78,3 +69,3 @@ setCache((cache) => {

urlRef.current = frameStateRef.current.url
return { [key]: next }
return {[key]: next}
}

@@ -85,3 +76,3 @@

if (!isEqual(prev, next)) {
return { ...cache, [key]: next }
return {...cache, [key]: next}
}

@@ -88,0 +79,0 @@

@@ -1,7 +0,4 @@

import { Dispatch, SetStateAction, useEffect, useState } from 'react'
import {type Dispatch, type SetStateAction, useEffect, useState} from 'react'
export function useLocalState<T>(
key: string,
defaultValue: T,
): [T, Dispatch<SetStateAction<T>>] {
export function useLocalState<T>(key: string, defaultValue: T): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState<T>(() =>

@@ -8,0 +5,0 @@ JSON.parse(localStorage.getItem(key) ?? JSON.stringify(defaultValue)),

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

import { MutableRefObject, useEffect, useMemo, useRef } from 'react'
import { getPublishedId } from 'sanity'
import { RouterContextValue, RouterState, SearchParam } from 'sanity/router'
import {type MutableRefObject, useEffect, useMemo, useRef} from 'react'
import {getPublishedId} from 'sanity'
import type {RouterContextValue, RouterState, SearchParam} from 'sanity/router'
import { debounce } from './lib/debounce'
import { parseRouterState } from './lib/parse'
import {
import {debounce} from './lib/debounce'
import {parseRouterState} from './lib/parse'
import type {
FrameState,

@@ -44,3 +44,3 @@ PresentationNavigate,

const params = useMemo<PresentationParams>(() => {
const { id, path, type } = parseRouterState(routerState)
const {id, path, type} = parseRouterState(routerState)

@@ -52,17 +52,16 @@ return {

preview:
routerSearchParams.preview ||
`${initialPreviewUrl.pathname}${initialPreviewUrl.search}`,
perspective: routerSearchParams.perspective,
viewport: routerSearchParams.viewport,
inspect: routerSearchParams.inspect,
rev: routerSearchParams.rev,
since: routerSearchParams.since,
template: routerSearchParams.template,
templateParams: routerSearchParams.templateParams,
view: routerSearchParams.view,
routerSearchParams['preview'] || `${initialPreviewUrl.pathname}${initialPreviewUrl.search}`,
perspective: routerSearchParams['perspective'],
viewport: routerSearchParams['viewport'],
inspect: routerSearchParams['inspect'],
rev: routerSearchParams['rev'],
since: routerSearchParams['since'],
template: routerSearchParams['template'],
templateParams: routerSearchParams['templateParams'],
view: routerSearchParams['view'],
// assist
pathKey: routerSearchParams.pathKey,
instruction: routerSearchParams.instruction,
pathKey: routerSearchParams['pathKey'],
instruction: routerSearchParams['instruction'],
// comments
comment: routerSearchParams.comment,
comment: routerSearchParams['comment'],
}

@@ -108,49 +107,42 @@ }, [routerState, routerSearchParams, initialPreviewUrl])

() =>
debounce<PresentationNavigate>(
(nextState, nextSearchState = {}, forceReplace) => {
// Force navigation to use published IDs only
if (nextState.id) nextState.id = getPublishedId(nextState.id)
debounce<PresentationNavigate>((nextState, nextSearchState = {}, forceReplace) => {
// Force navigation to use published IDs only
if (nextState.id) nextState.id = getPublishedId(nextState.id)
// Extract type, id and path as 'routerState'
const { _searchParams: routerSearchParams, ...routerState } =
routerStateRef.current
// 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
),
{} as PresentationSearchParams,
)
// Convert array of search params to an object
const routerSearchState = (routerSearchParams || []).reduce(
(acc, [key, value]) => ((acc[key as keyof PresentationSearchParams] = value), acc),
{} as PresentationSearchParams,
)
// Merge routerState and incoming state
const state: RouterState = pruneObject({
...routerState,
...nextState,
})
// Merge routerState and incoming state
const state: RouterState = pruneObject({
...routerState,
...nextState,
})
// Merge routerSearchState and incoming searchState
const searchState = pruneObject({
...routerSearchState,
...nextSearchState,
})
// Merge routerSearchState and incoming searchState
const searchState = pruneObject({
...routerSearchState,
...nextSearchState,
})
// If the document has changed, clear the template and templateParams
if (routerState.id !== state.id) {
delete searchState.template
delete searchState.templateParams
}
// If the document has changed, clear the template and templateParams
if (routerState.id !== state['id']) {
delete searchState.template
delete searchState.templateParams
}
state._searchParams = Object.entries(searchState).reduce(
(acc, [key, value]) => [...acc, [key, value]],
[] as SearchParam[],
)
state._searchParams = Object.entries(searchState).reduce(
(acc, [key, value]) => [...acc, [key, value]],
[] as SearchParam[],
)
const replace =
forceReplace ?? searchState.preview === frameStateRef.current.url
const replace = forceReplace ?? searchState.preview === frameStateRef.current.url
routerNavigate(state, { replace })
},
50,
),
routerNavigate(state, {replace})
}, 50),
[routerNavigate, frameStateRef],

@@ -157,0 +149,0 @@ )

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

import { useContext } from 'react'
import {useContext} from 'react'
import {
PresentationNavigateContext,
PresentationNavigateContextValue,
type PresentationNavigateContextValue,
} from './PresentationNavigateContext'

@@ -18,2 +18,2 @@

export type { PresentationNavigateContextValue }
export type {PresentationNavigateContextValue}

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

import { useContext } from 'react'
import {useContext} from 'react'
import { PresentationParamsContext } from './PresentationParamsContext'
import { PresentationParams } from './types'
import {PresentationParamsContext} from './PresentationParamsContext'
import type {PresentationParams} from './types'

@@ -6,0 +6,0 @@ export function usePresentationParams(): PresentationParams {

@@ -1,7 +0,4 @@

import { useContext } from 'react'
import {useContext} from 'react'
import {
PresentationContext,
PresentationContextValue,
} from './PresentationContext'
import {PresentationContext, type PresentationContextValue} from './PresentationContext'

@@ -8,0 +5,0 @@ export function usePresentationTool(): PresentationContextValue {

@@ -1,14 +0,9 @@

import { createPreviewSecret } from '@sanity/preview-url-secret/create-secret'
import { definePreviewUrl } from '@sanity/preview-url-secret/define-preview-url'
import { startTransition, useEffect, useMemo, useState } from 'react'
import {
type SanityClient,
useActiveWorkspace,
useClient,
useCurrentUser,
} from 'sanity'
import { suspend } from 'suspend-react'
import {createPreviewSecret} from '@sanity/preview-url-secret/create-secret'
import {definePreviewUrl} from '@sanity/preview-url-secret/define-preview-url'
import {startTransition, useEffect, useMemo, useState} from 'react'
import {type SanityClient, useActiveWorkspace, useClient, useCurrentUser} from 'sanity'
import {suspend} from 'suspend-react'
import { API_VERSION } from './constants'
import { PreviewUrlOption } from './types'
import {API_VERSION} from './constants'
import type {PreviewUrlOption} from './types'

@@ -20,3 +15,3 @@ export function usePreviewUrl(

): URL {
const client = useClient({ apiVersion: API_VERSION })
const client = useClient({apiVersion: API_VERSION})
const workspace = useActiveWorkspace()

@@ -52,4 +47,3 @@ const basePath = workspace?.activeWorkspace?.basePath || '/'

location.origin === resultUrl.origin &&
(resultUrl.pathname.startsWith(`${basePath}/`) ||
resultUrl.pathname === basePath)
(resultUrl.pathname.startsWith(`${basePath}/`) || resultUrl.pathname === basePath)
) {

@@ -61,5 +55,3 @@ return resolvedUrl

const resolvePreviewUrl =
typeof previewUrl === 'object'
? definePreviewUrl<SanityClient>(previewUrl)
: previewUrl
typeof previewUrl === 'object' ? definePreviewUrl<SanityClient>(previewUrl) : previewUrl
const resolvedUrl = await resolvePreviewUrl({

@@ -79,7 +71,3 @@ client,

function useSuspendCacheKeys(
toolName: string,
basePath: string,
workspaceName: string,
) {
function useSuspendCacheKeys(toolName: string, basePath: string, workspaceName: string) {
const currentUser = useCurrentUser()

@@ -100,7 +88,4 @@ return useMemo(

function usePreviewUrlSecret(
enabled: boolean,
deps: (string | symbol | undefined)[],
) {
const client = useClient({ apiVersion: API_VERSION })
function usePreviewUrlSecret(enabled: boolean, deps: (string | symbol | undefined)[]) {
const client = useClient({apiVersion: API_VERSION})
const currentUser = useCurrentUser()

@@ -123,5 +108,3 @@ const [secretLastExpiredAt, setSecretLastExpiredAt] = useState<string>('')

const timeout = setTimeout(() => {
startTransition(() =>
setSecretLastExpiredAt(previewUrlSecret.expiresAt.toString()),
)
startTransition(() => setSecretLastExpiredAt(previewUrlSecret.expiresAt.toString()))
}, previewUrlSecret.expiresAt.getTime() - Date.now())

@@ -128,0 +111,0 @@ return () => clearTimeout(timeout)

Sorry, the diff of this file is too big to display

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

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

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

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

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc