@nocode-factory/sanity-kit 2.20.0 → 2.20.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.20.0",
3
+ "version": "2.20.1",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -1,7 +1,7 @@
1
1
  import {useState, type ComponentType} from 'react'
2
2
  import {set, unset, useFormValue, useSchema, type InputProps} from 'sanity'
3
3
  import {useRouter} from 'sanity/router'
4
- import {Box, Flex, Stack, Text} from '@sanity/ui'
4
+ import {Box, Flex, Text} from '@sanity/ui'
5
5
  import {Tooltip} from '@sanity/ui/tooltip'
6
6
  import type {ResolvedKitConfig} from '../config/types'
7
7
  import {blockName, componentIntentParams} from '../lib/blocks'
@@ -62,36 +62,28 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
62
62
 
63
63
  const router = useRouter()
64
64
 
65
+ // UNE SEULE structure quel que soit l'état du champ (hérite, override, égal au
66
+ // défaut) : si l'enveloppe changeait à la première frappe (champ vide qui
67
+ // devient override), React recréerait le champ et le curseur sortirait.
65
68
  // Champ vide qui hérite : il affiche la valeur par défaut du composant
66
69
  // (grisée dans un champ texte, mentionnée sous les autres champs).
67
- if (isEmptyValue(inputProps.value) && !isEmptyValue(inherited)) {
68
- // Texte grisé seulement dans une zone de saisie libre (texte, nombre) ; un
69
- // choix (style, taille, variante, texture...) affiche la mention.
70
- const st = inputProps.schemaType as {jsonType?: string; options?: {list?: unknown[]}}
71
- const freeText = (st.jsonType === 'string' || st.jsonType === 'number') && !st.options?.list?.length
72
- const placeholder = freeText ? inheritedPlaceholder(inherited) : null
73
- const withPlaceholder =
74
- placeholder !== null
75
- ? ({...inputProps, elementProps: {...(inputProps.elementProps as object), placeholder}} as InputProps)
76
- : inputProps
77
- return (
78
- <Stack gap={2}>
79
- {inputProps.renderDefault(withPlaceholder)}
80
- {placeholder === null && (
81
- <Text size={0} muted>
82
- Valeur par défaut du composant : {describeValue(inherited)}
83
- </Text>
84
- )}
85
- </Stack>
86
- )
87
- }
70
+ const inherits = isEmptyValue(inputProps.value) && !isEmptyValue(inherited)
71
+ // Texte grisé seulement dans une zone de saisie libre (texte, nombre) ; un
72
+ // choix (style, taille, variante, texture...) affiche la mention.
73
+ const st = inputProps.schemaType as {jsonType?: string; options?: {list?: unknown[]}}
74
+ const freeText = (st.jsonType === 'string' || st.jsonType === 'number') && !st.options?.list?.length
75
+ const placeholder = inherits && freeText ? inheritedPlaceholder(inherited) : null
76
+ const shown =
77
+ placeholder !== null
78
+ ? ({...inputProps, elementProps: {...(inputProps.elementProps as object), placeholder}} as InputProps)
79
+ : inputProps
88
80
 
89
- if (!isOverride(inputProps.value, inherited, field, parent)) return inputProps.renderDefault(inputProps)
90
81
  // « Réinitialiser » remet le champ en HÉRITAGE (vidé en base) : il suit la
91
82
  // valeur par défaut, aujourd'hui comme après ses changements. Sans valeur par
92
83
  // défaut : ouvre le réglage du composant (un champ vidé n'afficherait rien).
93
84
  // Élément de liste : la liste remplie remplace celle du défaut en entier, la
94
85
  // valeur par défaut y est donc recopiée.
86
+ const override = !inherits && isOverride(inputProps.value, inherited, field, parent)
95
87
  const action = resetAction(inherited)
96
88
  const onClick =
97
89
  action.kind === 'noDefault'
@@ -106,9 +98,16 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
106
98
  return (
107
99
  <Flex align="flex-start" gap={2}>
108
100
  <Box flex={1} style={{minWidth: 0}}>
109
- {inputProps.renderDefault(inputProps)}
101
+ {inputProps.renderDefault(shown)}
102
+ {inherits && placeholder === null && (
103
+ <Box marginTop={2}>
104
+ <Text size={0} muted>
105
+ Valeur par défaut du composant : {describeValue(inherited)}
106
+ </Text>
107
+ </Box>
108
+ )}
110
109
  </Box>
111
- <OverrideDot hasDefault={action.kind !== 'noDefault'} full={describeValue(inherited)} short={shortValue(inherited)} onClick={onClick} />
110
+ {override && <OverrideDot hasDefault={action.kind !== 'noDefault'} full={describeValue(inherited)} short={shortValue(inherited)} onClick={onClick} />}
112
111
  </Flex>
113
112
  )
114
113
  }
@@ -21,18 +21,19 @@ export function createSlugUrlInput(config: ResolvedKitConfig): ComponentType<Inp
21
21
  const path = pageType ? toPath({slug, path: pageType.path, pathPrefix: pageType.pathPrefix, locale}, config.i18n) : null
22
22
  const url = toUrl(config.previewUrl, path)
23
23
 
24
- if (!url) return props.renderDefault(props)
25
-
26
24
  const copy = () => {
25
+ if (!url) return
27
26
  void navigator.clipboard.writeText(url).then(() => {
28
27
  setCopied(true)
29
28
  window.setTimeout(() => setCopied(false), 1500)
30
29
  })
31
30
  }
32
31
 
32
+ // Même structure avec ou sans adresse : le champ n'est jamais recréé pendant la frappe.
33
33
  return (
34
34
  <Stack gap={2}>
35
35
  {props.renderDefault(props)}
36
+ {url && (
36
37
  <Card tone="primary" padding={2} radius={2} border>
37
38
  <Flex align="center" gap={2}>
38
39
  <Text size={1} muted style={{flex: 1, minWidth: 0, wordBreak: 'break-all'}}>
@@ -42,6 +43,7 @@ export function createSlugUrlInput(config: ResolvedKitConfig): ComponentType<Inp
42
43
  <Button as="a" href={url} target="_blank" rel="noopener noreferrer" mode="ghost" fontSize={1} padding={2} text="Ouvrir" />
43
44
  </Flex>
44
45
  </Card>
46
+ )}
45
47
  </Stack>
46
48
  )
47
49
  }
@@ -17,8 +17,9 @@ export function withTranslationTodo(Inner: ComponentType<InputProps>, config: Re
17
17
  const [busy, setBusy] = useState(false)
18
18
  const key = fieldPathKey(props.path)
19
19
  const inner = createElement(Inner, props)
20
- if (!todo?.paths?.includes(key)) return inner
20
+ const show = Boolean(todo?.paths?.includes(key))
21
21
  const done = () => {
22
+ if (!todo) return
22
23
  setBusy(true)
23
24
  void client
24
25
  .patch(todo._id)
@@ -26,17 +27,20 @@ export function withTranslationTodo(Inner: ComponentType<InputProps>, config: Re
26
27
  .commit()
27
28
  .finally(() => setBusy(false))
28
29
  }
30
+ // Même structure que la mention soit là ou non : le champ n'est jamais recréé.
29
31
  return (
30
32
  <Stack gap={2}>
31
33
  {inner}
34
+ {show && (
32
35
  <Card tone="caution" padding={2} radius={2} border>
33
36
  <Flex align="center" gap={2}>
34
37
  <Text size={1} style={{flex: 1}}>
35
- À traduire : modifié dans la version {(todo.sourceLanguage ?? '').toUpperCase()}.
38
+ À traduire : modifié dans la version {(todo?.sourceLanguage ?? '').toUpperCase()}.
36
39
  </Text>
37
40
  <Button mode="ghost" fontSize={1} padding={2} text="Marquer comme traduit" disabled={busy} onClick={done} />
38
41
  </Flex>
39
42
  </Card>
43
+ )}
40
44
  </Stack>
41
45
  )
42
46
  }
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
4
4
  * le vérifie.
5
5
  */
6
- export const KIT_VERSION = '2.20.0'
6
+ export const KIT_VERSION = '2.20.1'