@nocode-factory/sanity-kit 2.10.1 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/form/OverrideInput.tsx +5 -0
- package/src/hooks/useInPresentation.ts +26 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import {blockName, componentIntentParams} from '../lib/blocks'
|
|
|
8
8
|
import {useKitClient} from '../hooks/useKitClient'
|
|
9
9
|
import {openComponentDefaults} from '../lib/openComponent'
|
|
10
10
|
import {useComponentDefaults} from '../hooks/useComponentDefaults'
|
|
11
|
+
import {useInPresentation} from '../hooks/useInPresentation'
|
|
11
12
|
import {
|
|
12
13
|
defaultValueAt,
|
|
13
14
|
describeValue,
|
|
@@ -128,10 +129,14 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
|
|
|
128
129
|
// En tête du formulaire d'une instance de composant : mène aux valeurs par
|
|
129
130
|
// défaut du composant (son « instance principale »), qui s'appliquent à toutes
|
|
130
131
|
// les instances dont le champ est vide.
|
|
132
|
+
// Pas dans Presentation : on y édite une instance à côté de son rendu, et quitter la
|
|
133
|
+
// page pour les valeurs par défaut y prête à confusion (bouton retiré à la demande).
|
|
131
134
|
function WithMainInstance(props: InputProps & {type: string}) {
|
|
132
135
|
const {type, ...inputProps} = props
|
|
133
136
|
const client = useKitClient()
|
|
134
137
|
const router = useRouter()
|
|
138
|
+
const inPresentation = useInPresentation()
|
|
139
|
+
if (inPresentation) return inputProps.renderDefault(inputProps)
|
|
135
140
|
const open = () =>
|
|
136
141
|
void openComponentDefaults({type, config, hasDefaults: true, client, navigateIntent: (i, p) => router.navigateIntent(i, p)})
|
|
137
142
|
return (
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {useWorkspace} from 'sanity'
|
|
2
|
+
import {useRouterState} from 'sanity/router'
|
|
3
|
+
|
|
4
|
+
/** Noms des outils Presentation du workspace (le nom est configurable). */
|
|
5
|
+
export function presentationToolNames(tools: {name: string}[]): string[] {
|
|
6
|
+
return tools
|
|
7
|
+
.filter((t) => (t as {__internalApplicationType?: string}).__internalApplicationType === 'sanity/presentation' || t.name === 'presentation')
|
|
8
|
+
.map((t) => t.name)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Vrai si l'adresse du Studio est dans un de ces outils (premier segment après la base). */
|
|
12
|
+
export function isInTool(pathname: string, names: string[]): boolean {
|
|
13
|
+
return pathname.split('/').some((segment) => names.includes(segment))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Le formulaire est-il affiché dans Presentation ? Le routeur sert à se mettre à jour
|
|
18
|
+
* quand on change d'outil ; l'adresse dit lequel (le formulaire de Presentation est rendu
|
|
19
|
+
* dans la portée de son outil, qui ne porte pas le nom de l'outil).
|
|
20
|
+
*/
|
|
21
|
+
export function useInPresentation(): boolean {
|
|
22
|
+
const {tools} = useWorkspace()
|
|
23
|
+
useRouterState()
|
|
24
|
+
if (typeof window === 'undefined') return false
|
|
25
|
+
return isInTool(window.location.pathname, presentationToolNames(tools))
|
|
26
|
+
}
|
package/src/version.ts
CHANGED